--- loncom/interface/loncreateuser.pm 2014/02/19 17:12:52 1.394 +++ loncom/interface/loncreateuser.pm 2016/10/04 21:02:16 1.414 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.394 2014/02/19 17:12:52 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.414 2016/10/04 21:02:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -251,13 +251,15 @@ sub build_tools_display { 'unofficial' => 'Can request creation of unofficial courses', 'community' => 'Can request creation of communities', 'textbook' => 'Can request creation of textbook courses', + 'placement' => 'Can request creation of placement tests', 'requestauthor' => 'Can request author space', ); if ($context eq 'requestcourses') { %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, 'requestcourses.official','requestcourses.unofficial', - 'requestcourses.community','requestcourses.textbook'); - @usertools = ('official','unofficial','community','textbook'); + 'requestcourses.community','requestcourses.textbook', + 'requestcourses.placement'); + @usertools = ('official','unofficial','community','textbook','placement'); @options =('norequest','approval','autolimit','validate'); %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain); %reqtitles = &courserequest_titles(); @@ -447,12 +449,14 @@ sub coursereq_externaluser { 'unofficial' => 'Can request creation of unofficial courses', 'community' => 'Can request creation of communities', 'textbook' => 'Can request creation of textbook courses', + 'placement' => 'Can request creation of placement tests', ); %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, 'reqcrsotherdom.official','reqcrsotherdom.unofficial', - 'reqcrsotherdom.community','reqcrsotherdom.textbook'); - @usertools = ('official','unofficial','community','textbook'); + 'reqcrsotherdom.community','reqcrsotherdom.textbook', + 'reqcrsotherdom.placement'); + @usertools = ('official','unofficial','community','textbook','placement'); @options = ('approval','validate','autolimit'); %validations = &Apache::lonnet::auto_courserequest_checks($cdom); my $optregex = join('|',@options); @@ -527,12 +531,79 @@ sub domainrole_req { &Apache::loncommon::end_data_table(); } +sub domadhocroles { + my ($ccuname,$ccdomain) = @_; + my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'}); + my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'}, + $confname,'rolesdef_'); + my $output; + if (keys(%existing) > 0) { + my @current; + my $curradhoc = 'adhocroles.'.$env{'request.role.domain'}; + my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,$curradhoc); + if ($userenv{$curradhoc}) { + @current = split(/,/,$userenv{$curradhoc}); + } + my %customroles; + foreach my $key (keys(%existing)) { + if ($key=~/^rolesdef\_(\w+)$/) { + my $rolename = $1; + my %privs; + ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key}); + $customroles{$rolename} = \%privs; + } + } + $output = '<br /><h3>'. + &mt('Ad Hoc Course Roles Selectable via Helpdesk Role'). + '</h3>'."\n". + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + '<th>'.&mt('Action').'</th><th>'.&mt('Role').'</th>'. + '<th>'.&mt('Privileges in Course').'<th>'. + &Apache::loncommon::end_data_table_header_row(); + foreach my $key (sort(keys(%customroles))) { + $output .= &Apache::loncommon::start_data_table_row(); + if (grep(/^\Q$key\E$/,@current)) { + $output .= '<td><label>'. + '<input type="checkbox" name="adhocroledel" value="'.$key.'" />'. + &mt('Delete').'</label>'. + '</td>'; + } else { + $output .= '<td><label>'. + '<input type="checkbox" name="adhocroleadd" value="'.$key.'" />'. + &mt('Add').'</label>'. + '</td>'; + } + $output .= '<td>'.$key.'</td><td>'; + foreach my $level ('course','domain','system') { + if ($customroles{$key}{$level}) { + my $suffix; + if (($level eq 'domain') || ($level eq 'system')) { + $suffix = ' ('.&mt($level).')'; + } + my @privs = split(/:/,$customroles{$key}{$level}); + foreach my $item (@privs) { + next if ($item eq ''); + my ($priv,$cond) = split(/\&/,$item); + $output .= &Apache::lonnet::plaintext($priv,'Course').$suffix.'<br />'; + } + } + } + $output .= '</td>'. + &Apache::loncommon::end_data_table_row(); + } + $output .= &Apache::loncommon::end_data_table(); + } + return $output; +} + sub courserequest_titles { my %titles = &Apache::lonlocal::texthash ( official => 'Official', unofficial => 'Unofficial', community => 'Communities', textbook => 'Textbook', + placement => 'Placement Tests', norequest => 'Not allowed', approval => 'Approval by Dom. Coord.', validate => 'With validation', @@ -813,7 +884,7 @@ sub entry_form { } my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context,$usertype); - my $userpicker = + my ($userpicker,$cansearch) = &Apache::loncommon::user_picker($dom,$srch,$forcenewuser, 'document.crtuser',$cancreate,$usertype); my $srchbutton = &mt('Search'); @@ -822,7 +893,9 @@ sub entry_form { } elsif ($cancreate && $responsemsg ne '' && $inexact) { $srchbutton = &mt('Search or Add New User'); } - my $output = <<"ENDBLOCK"; + my $output; + if ($cansearch) { + $output = <<"ENDBLOCK"; <form action="/adm/createuser" method="post" name="crtuser"> <input type="hidden" name="action" value="$env{'form.action'}" /> <input type="hidden" name="phase" value="get_user_info" /> @@ -830,6 +903,9 @@ $userpicker <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" /> </form> ENDBLOCK + } else { + $output = '<p>'.$userpicker.'</p>'; + } if ($env{'form.phase'} eq '') { my $defdom=$env{'request.role.domain'}; my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain'); @@ -1231,7 +1307,7 @@ ENDFORMINFO } my $title = ''; if ($newuser) { - my ($portfolioform,$domroleform); + my ($portfolioform,$domroleform,$adhocroleform); if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) || (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) { # Current user has quota or user tools modification privileges @@ -1241,6 +1317,12 @@ ENDFORMINFO ($ccdomain eq $env{'request.role.domain'})) { $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain); } + if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) { + $adhocroleform = &domadhocroles($ccuname,$ccdomain); + if ($adhocroleform) { + $adhocroleform = '<br />'.$adhocroleform; + } + } &initialize_authen_forms($ccdomain,$formname); my %lt=&Apache::lonlocal::texthash( 'lg' => 'Login Data', @@ -1351,7 +1433,7 @@ ENDAUTH } else { $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc)); } - $r->print($portfolioform.$domroleform); + $r->print($portfolioform.$domroleform.$adhocroleform); if ($env{'form.action'} eq 'singlestudent') { $r->print(&date_sections_select($context,$newuser,$formname, $permission,$crstype,$ccuname, @@ -1388,7 +1470,7 @@ ENDAUTH $r->print(&Apache::loncommon::end_data_table()); } $r->print('</div>'); - my @order = ('auth','quota','tools','requestauthor'); + my @order = ('auth','quota','tools','requestauthor','adhocroles'); my %user_text; my ($isadv,$isauthor) = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain); @@ -1397,6 +1479,9 @@ ENDAUTH && ($env{'request.role.domain'} eq $ccdomain)) { $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain); } + if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) { + $user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain); + } $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname); if ((&Apache::lonnet::allowed('mpq',$ccdomain)) || (&Apache::lonnet::allowed('mut',$ccdomain))) { @@ -1813,7 +1898,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); @@ -2164,7 +2249,7 @@ sub modify_login_block { sub personal_data_display { my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray, - $now,$captchaform,$emailusername) = @_; + $now,$captchaform,$emailusername,$usertype) = @_; my ($output,%userenv,%canmodify,%canmodify_status); my @userinfo = ('firstname','middlename','lastname','generation', 'permanentemail','id'); @@ -2206,19 +2291,24 @@ sub personal_data_display { \@userinfo,$rolesarray); } elsif ($context eq 'selfcreate') { if ($newuser eq 'email') { - if (ref($emailusername) 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->{$field}) { - push(@userinfo,$field); - $canmodify{$field} = 1; - unless ($textboxsize{$field}) { - $textboxsize{$field} = 25; - } - unless ($lt{$field}) { - $lt{$field} = $infotitles->{$field}; + 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>'; + } } } } @@ -2234,19 +2324,19 @@ sub personal_data_display { $output = '<h3>'.$lt{'pd'}.'</h3>'. &Apache::lonhtmlcommon::start_pick_box(); if (($context eq 'selfcreate') && ($newuser eq 'email')) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'email'},undef, + $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="10" autocomplete="off" />'; - my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" autocomplete="off" />'; - $output .= &Apache::lonhtmlcommon::row_title(&mt('Password'), + 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'), + &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>', 'LC_pick_box_title', 'LC_oddrow_value')."\n". $upasstwo. @@ -2277,19 +2367,15 @@ sub personal_data_display { } } else { if ($context eq 'selfcreate') { - if (($item eq 'permanentemail') && ($newuser eq 'email')) { - $row .= $ccuname; - } else { - if ($canmodify{$item}) { - if ($newuser eq 'email') { - $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; - } else { - $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; - } - $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="" />'; @@ -2350,7 +2436,7 @@ sub personal_data_display { } if (($context eq 'selfcreate') && ($newuser eq 'email')) { if ($captchaform) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}, + $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*', 'LC_pick_box_title')."\n". $captchaform."\n".'<br /><br />'. &Apache::lonhtmlcommon::row_closure(1); @@ -2360,6 +2446,7 @@ sub personal_data_display { $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(); @@ -2577,7 +2664,7 @@ sub update_user_data { my (%alerts,%rulematch,%inst_results,%curr_rules); my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); my @usertools = ('aboutme','blog','webdav','portfolio'); - my @requestcourses = ('official','unofficial','community','textbook'); + my @requestcourses = ('official','unofficial','community','textbook','placement'); my @requestauthor = ('requestauthor'); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'}); @@ -2687,6 +2774,12 @@ sub update_user_data { $newcustom{'requestauthor'}, \%changeHash,'requestauthor'); } + if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) { + my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd'); + if (&adhocrole_changes(\%changeHash)) { + $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}}; + } + } } if ($canmodify_status{'inststatus'}) { if (exists($env{'form.inststatus'})) { @@ -2715,7 +2808,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( @@ -2725,7 +2818,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 @@ -2750,7 +2843,8 @@ sub update_user_data { 'requestcourses.community','requestcourses.textbook', 'reqcrsotherdom.official','reqcrsotherdom.unofficial', 'reqcrsotherdom.community','reqcrsotherdom.textbook', - 'requestauthor'], + 'reqcrsotherdom.placement','requestauthor', + 'adhocroles.'.$env{'request.role.domain'}], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { @@ -2889,6 +2983,7 @@ sub update_user_data { &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name); ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name}); } + push(@disporder,'adhocroles'); my %canshow; if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { $canshow{'quota'} = 1; @@ -2907,6 +3002,9 @@ sub update_user_data { if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) { $canshow{'requestauthor'} = 1; } + if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) { + $canshow{'adhocroles'} = 1; + } my (%changeHash,%changed); if ($oldinststatus eq '') { $oldsettings{'inststatus'} = $othertitle; @@ -3020,6 +3118,14 @@ sub update_user_data { &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext, \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); } + if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) { + $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}}; + } + if (&adhocrole_changes(\%changeHash,\%userenv)) { + $changed{'adhocroles'} = 1; + $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}}; + $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}}; + } } foreach my $item (@userinfo) { if ($env{'form.c'.$item} ne $userenv{$item}) { @@ -3041,8 +3147,9 @@ sub update_user_data { ($env{'user.domain'} eq $env{'form.ccdomain'})) { my %newenvhash; foreach my $key (keys(%changed)) { - if (($key eq 'official') || ($key eq 'unofficial') - || ($key eq 'community')) { + if (($key eq 'official') || ($key eq 'unofficial') || + ($key eq 'community') || ($key eq 'textbook') || + ($key eq 'placement')) { $newenvhash{'environment.requestcourses.'.$key} = $changeHash{'requestcourses.'.$key}; if ($changeHash{'requestcourses.'.$key}) { @@ -3061,6 +3168,9 @@ sub update_user_data { &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','requestauthor'); } + } elsif ($key eq 'adhocroles') { + $newenvhash{'adhocroles.'.$env{'request.role.domain'}} = + $changeHash{'adhocroles.'.$env{'request.role.domain'}}; } elsif ($key ne 'quota') { $newenvhash{'environment.tools.'.$key} = $changeHash{'tools.'.$key}; @@ -3108,7 +3218,7 @@ sub update_user_data { \%newsettingstext); if ($env{'form.cid'} ne $userenv{'id'}) { &Apache::lonnet::idput($env{'form.ccdomain'}, - ($env{'form.ccuname'} => $env{'form.cid'})); + {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids'); if (($recurseid) && (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) { my $idresult = @@ -3150,9 +3260,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(); @@ -3161,9 +3271,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 />' @@ -3251,7 +3361,9 @@ sub display_userinfo { 'unofficial' => 'Can Request Unofficial Courses', 'community' => 'Can Request Communities', 'textbook' => 'Can Request Textbook Courses', + 'placement' => 'Can Request Placement Tests', 'requestauthor' => 'Can Request Author Role', + 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role', 'inststatus' => "Affiliation", 'prvs' => 'Previous Value:', 'chto' => 'Changed To:' @@ -3617,13 +3729,77 @@ sub tool_changes { return; } +sub adhocrole_changes { + my ($changehashref,$userenv) = @_; + my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd'); + my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel'); + my (@saved,@added,@alladhoc,$changed); + my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'}; + if (!$env{'form.makeuser'}) { + if (ref($userenv) eq 'HASH') { + my @current; + if ($userenv->{$adhoc_key}) { + @current = split(/,/,$userenv->{$adhoc_key}); + if (@dels) { + foreach my $curr (@current) { + next if ($curr eq ''); + unless (grep(/\Q$curr\E$/,@dels)) { + push(@saved,$curr); + } + } + $changed = 1; + } else { + @saved = @current; + } + } + } + } + if (@adds) { + my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'}); + my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'}, + $confname,'rolesdef_'); + foreach my $poss (@adds) { + if (exists($existing{'rolesdef_'.$poss})) { + push(@added,$poss); + $changed = 1; + } + } + } + if (@added) { + if (@saved) { + foreach my $add (@added) { + unless (grep(/^\Q$add\E$/,@saved)) { + push(@alladhoc,$add); + } + } + } else { + push(@alladhoc,@added); + } + } + if (@saved) { + push(@alladhoc,@saved); + } + if (@alladhoc) { + my $adhocstr = join(',',sort(@alladhoc)); + $changehashref->{$adhoc_key} = $adhocstr; + } elsif (@dels) { + &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'}); + delete($changehashref->{$adhoc_key}); + if (($env{'form.ccdomain'} eq $env{'user.domain'}) && + ($env{'form.ccuname'} eq $env{'user.name'})) { + &Apache::lonnet::delenv($adhoc_key); + } + } + return $changed; +} + sub update_roles { my ($r,$context,$showcredits) = @_; my $now=time; 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 @@ -3805,7 +3981,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; @@ -3851,7 +4027,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') || @@ -3891,7 +4067,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)); @@ -4147,7 +4323,7 @@ sub build_roles { # ========================================================== Custom Role Editor sub custom_role_editor { - my ($r,$brcrum) = @_; + my ($r,$brcrum,$prefix) = @_; my $action = $env{'form.customroleaction'}; my $rolename; if ($action eq 'new') { @@ -4162,7 +4338,7 @@ sub custom_role_editor { $context = 'course'; } else { $context = 'domain'; - $crstype = $env{'form.templatecrstype'}; + $crstype = 'course'; } $rolename=~s/[^A-Za-z0-9]//gs; @@ -4171,120 +4347,54 @@ sub custom_role_editor { return; } -# ------------------------------------------------------- What can be assigned? - my %full=(); - my %courselevel=(); - my %courselevelcurrent=(); - my $syspriv=''; - my $dompriv=''; - my $coursepriv=''; - my $body_top; - my $newrole; + my $formname = 'form1'; + my %privs=(); + my $body_top = '<h2>'; +# ------------------------------------------------------- Does this role exist? my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); -# ------------------------------------------------------- Does this role exist? - $body_top .= '<h2>'; if (($rdummy ne 'con_lost') && ($roledef ne '')) { - $body_top .= &mt('Existing Role').' "'; + $body_top .= &mt('Existing Role').' "'; # ------------------------------------------------- Get current role privileges - ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef); - if ($crstype eq 'Community') { - $syspriv =~ s/bre\&S//; + ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef); + if ($privs{'system'} =~ /bre\&S/) { + if ($context eq 'domain') { + $crstype = 'Course'; + } elsif ($crstype eq 'Community') { + $privs{'system'} =~ s/bre\&S//; + } + } elsif ($context eq 'domain') { + $crstype = 'Course'; } } else { - $newrole = 1; - $body_top .= &mt('New Role').' "'; - $roledef=''; + $body_top .= &mt('New Role').' "'; + $roledef=''; } $body_top .= $rolename.'"</h2>'; - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict='F'; } - $courselevel{$priv}=$restrict; - if ($coursepriv=~/\:$priv/) { - $courselevelcurrent{$priv}=1; - } - $full{$priv}=1; - } - my %domainlevel=(); - my %domainlevelcurrent=(); - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict='F'; } - $domainlevel{$priv}=$restrict; - if ($dompriv=~/\:$priv/) { - $domainlevelcurrent{$priv}=1; - } - $full{$priv}=1; - } - my %systemlevel=(); - my %systemlevelcurrent=(); - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict='F'; } - $systemlevel{$priv}=$restrict; - if ($syspriv=~/\:$priv/) { - $systemlevelcurrent{$priv}=1; - } - $full{$priv}=1; - } + +# ------------------------------------------------------- What can be assigned? + my %full=(); + my %levels=( + course => {}, + domain => {}, + system => {}, + ); + my %levelscurrent=( + course => {}, + domain => {}, + system => {}, + ); + &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent); my ($jsback,$elements) = &crumb_utilities(); - my $button_code = "\n"; - my $head_script = "\n"; - $head_script .= '<script type="text/javascript">'."\n" - .'// <![CDATA['."\n"; - my @template_roles = ("in","ta","ep"); - if ($context eq 'domain') { - push(@template_roles,"ad"); - } - push(@template_roles,"st"); - if ($crstype eq 'Community') { - unshift(@template_roles,'co'); - } else { - unshift(@template_roles,'cc'); - } - foreach my $role (@template_roles) { - $head_script .= &make_script_template($role,$crstype); - $button_code .= &make_button_code($role,$crstype).' '; - } - my $context_code; - if ($context eq 'domain') { - my $checkedCommunity = ''; - my $checkedCourse = ' checked="checked"'; - if ($env{'form.templatecrstype'} eq 'Community') { - $checkedCommunity = $checkedCourse; - $checkedCourse = ''; - } - $context_code = '<label>'. - '<input type="radio" name="templatecrstype" value="Course"'.$checkedCourse.' onclick="this.form.submit();">'. - &mt('Course'). - '</label>'.(' ' x2). - '<label>'. - '<input type="radio" name="templatecrstype" value="Community"'.$checkedCommunity.' onclick="this.form.submit();">'. - &mt('Community'). - '</label>'. - '</fieldset>'. - '<input type="hidden" name="customroleaction" value="'. - $action.'" />'; - if ($env{'form.customroleaction'} eq 'new') { - $context_code .= '<input type="hidden" name="newrolename" value="'. - $rolename.'" />'; - } else { - $context_code .= '<input type="hidden" name="rolename" value="'. - $rolename.'" />'; - } - $context_code .= '<input type="hidden" name="action" value="custom" />'. - '<input type="hidden" name="phase" value="selected_custom_edit" />'; - } - - $head_script .= "\n".$jsback."\n" - .'// ]]>'."\n" - .'</script>'."\n"; + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + my $head_script = + &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname, + \%full,\@templateroles,$jsback); push (@{$brcrum}, - {href => "javascript:backPage(document.form1,'pickrole','')", + {href => "javascript:backPage(document.$formname,'pickrole','')", text => "Pick custom role", faq => 282,bug=>'Instructor Interface',}, - {href => "javascript:backPage(document.form1,'','')", + {href => "javascript:backPage(document.$formname,'','')", text => "Edit custom role", faq => 282, bug => 'Instructor Interface', @@ -4296,57 +4406,16 @@ sub custom_role_editor { $r->print(&Apache::loncommon::start_page('Custom Role Editor', $head_script,$args). $body_top); - my %lt=&Apache::lonlocal::texthash( - 'prv' => "Privilege", - 'crl' => "Course Level", - 'dml' => "Domain Level", - 'ssl' => "System Level"); - - $r->print('<div class="LC_left_float">' - .'<form action=""><fieldset>' - .'<legend>'.&mt('Select a Template').'</legend>' - .$button_code - .'</fieldset></form></div>'); - if ($context_code) { - $r->print('<div class="LC_left_float">' - .'<form action="/adm/createuser" method="post"><fieldset>' - .'<legend>'.&mt('Context').'</legend>' - .$context_code - .'</form>' - .'</div>' - ); - } - $r->print('<br clear="all" />'); + $r->print('<form name="'.$formname.'" method="post" action="">'."\n". + &Apache::lonuserutils::custom_role_header($context,$crstype, + \@templateroles,$prefix)); $r->print(<<ENDCCF); -<form name="form1" method="post" action=""> <input type="hidden" name="phase" value="set_custom_roles" /> <input type="hidden" name="rolename" value="$rolename" /> ENDCCF - $r->print(&Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). -'<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}. -'</th><th>'.$lt{'ssl'}.'</th>'. - &Apache::loncommon::end_data_table_header_row()); - foreach my $priv (sort(keys(%full))) { - my $privtext = &Apache::lonnet::plaintext($priv,$crstype); - $r->print(&Apache::loncommon::start_data_table_row(). - '<td>'.$privtext.'</td><td>'. - ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'. - ($courselevelcurrent{$priv}?' checked="checked"':'').' />':' '). - '</td><td>'. - ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'. - ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':' '). - '</td><td>'); - if ($priv eq 'bre' && $crstype eq 'Community') { - $r->print(' '); - } else { - $r->print($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'. - ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':' '); - } - $r->print('</td>'. - &Apache::loncommon::end_data_table_row()); - } + $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels, + \%levelscurrent,$prefix)); $r->print(&Apache::loncommon::end_data_table(). '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'. '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}. @@ -4354,87 +4423,14 @@ ENDCCF '<input type="reset" value="'.&mt("Reset").'" />'."\n". '<input type="submit" value="'.&mt('Save').'" /></form>'); } -# -------------------------------------------------------- -sub make_script_template { - my ($role,$crstype) = @_; - my %full_c=(); - my %full_d=(); - my %full_s=(); - my $return_script; - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { - my ($priv,$restrict)=split(/\&/,$item); - $full_c{$priv}=1; - } - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { - my ($priv,$restrict)=split(/\&/,$item); - $full_d{$priv}=1; - } - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { - next if (($crstype eq 'Community') && ($item eq 'bre&S')); - my ($priv,$restrict)=split(/\&/,$item); - $full_s{$priv}=1; - } - $return_script .= 'function set_'.$role.'() {'."\n"; - my @temp = split(/:/,$Apache::lonnet::pr{$role.':c'}); - my %role_c; - foreach my $priv (@temp) { - my ($priv_item, $dummy) = split(/\&/,$priv); - $role_c{$priv_item} = 1; - } - my %role_d; - @temp = split(/:/,$Apache::lonnet::pr{$role.':d'}); - foreach my $priv(@temp) { - my ($priv_item, $dummy) = split(/\&/,$priv); - $role_d{$priv_item} = 1; - } - my %role_s; - @temp = split(/:/,$Apache::lonnet::pr{$role.':s'}); - foreach my $priv(@temp) { - my ($priv_item, $dummy) = split(/\&/,$priv); - $role_s{$priv_item} = 1; - } - foreach my $priv_item (keys(%full_c)) { - my ($priv, $dummy) = split(/\&/,$priv_item); - if ((exists($role_c{$priv})) || (exists($role_d{$priv})) || - (exists($role_s{$priv}))) { - $return_script .= "document.form1.$priv"."_c.checked = true;\n"; - } else { - $return_script .= "document.form1.$priv"."_c.checked = false;\n"; - } - } - foreach my $priv_item (keys(%full_d)) { - my ($priv, $dummy) = split(/\&/,$priv_item); - if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) { - $return_script .= "document.form1.$priv"."_d.checked = true;\n"; - } else { - $return_script .= "document.form1.$priv"."_d.checked = false;\n"; - } - } - foreach my $priv_item (keys(%full_s)) { - my ($priv, $dummy) = split(/\&/,$priv_item); - if (exists($role_s{$priv})) { - $return_script .= "document.form1.$priv"."_s.checked = true;\n"; - } else { - $return_script .= "document.form1.$priv"."_s.checked = false;\n"; - } - } - $return_script .= '}'."\n"; - return ($return_script); -} -# ---------------------------------------------------------- -sub make_button_code { - my ($role,$crstype) = @_; - my $label = &Apache::lonnet::plaintext($role,$crstype); - my $button_code = '<input type="button" onclick="set_'.$role.'()" value="'.$label.'" />'; - return ($button_code); -} + # ---------------------------------------------------------- Call to definerole sub set_custom_role { - my ($r,$context,$brcrum) = @_; + my ($r,$context,$brcrum,$prefix) = @_; my $rolename=$env{'form.rolename'}; $rolename=~s/[^A-Za-z0-9]//gs; if (!$rolename) { - &custom_role_editor($r,$brcrum); + &custom_role_editor($r,$brcrum,$prefix); return; } my ($jsback,$elements) = &crumb_utilities(); @@ -4459,7 +4455,7 @@ sub set_custom_role { help => 'Course_Editing_Custom_Roles'}, ); my $args = { bread_crumbs => $brcrum, - bread_crumbs_component => 'User Management'}; + bread_crumbs_component => 'User Management'}; $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args)); my $newrole; @@ -4476,38 +4472,13 @@ sub set_custom_role { $newrole = 1; } $r->print($rolename.'"</h3>'); -# ------------------------------------------------------- What can be assigned? - my $sysrole=''; - my $domrole=''; - my $courole=''; - - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict=''; } - if ($env{'form.'.$priv.'_c'}) { - $courole.=':'.$item; - } - } +# ------------------------------------------------- Assign role and show result - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict=''; } - if ($env{'form.'.$priv.'_d'}) { - $domrole.=':'.$item; - } - } - - foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { - my ($priv,$restrict)=split(/\&/,$item); - if (!$restrict) { $restrict=''; } - if ($env{'form.'.$priv.'_s'}) { - $sysrole.=':'.$item; - } - } - # Assign role; Compile and show result my $errmsg; - my $result = - &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole); + my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix); + # Assign role and return result + my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'}, + $newprivs{'c'}); if ($result ne 'ok') { $errmsg = ': '.$result; } @@ -4714,10 +4685,11 @@ sub handler { $brcrum); } } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) { + my $prefix; if ($env{'form.phase'} eq 'set_custom_roles') { - &set_custom_role($r,$context,$brcrum); + &set_custom_role($r,$context,$brcrum,$prefix); } else { - &custom_role_editor($r,$brcrum); + &custom_role_editor($r,$brcrum,$prefix); } } elsif (($env{'form.action'} eq 'processauthorreq') && ($permission->{'cusr'}) && @@ -4816,26 +4788,47 @@ sub handler { if (ref($domconfig{'usercreation'}) eq 'HASH') { if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') { - my $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}})); my %info = &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser); if (ref($info{$uname}) eq 'HASH') { - if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) { - $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box()); - my $num; - foreach my $field (@{$infofields}) { - next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$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()); + 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(&Apache::lonhtmlcommon::end_pick_box().'</div>'); } } } @@ -4948,25 +4941,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}, @@ -5353,6 +5370,7 @@ sub print_main_menu { groups => 'Community Groups', }, ); + $linktext{'Placement'} = $linktext{'Course'}; my %linktitle = ( 'Course' => { @@ -5367,6 +5385,8 @@ sub print_main_menu { }, ); + $linktitle{'Placement'} = $linktitle{'Course'}; + push(@{ $menu[0]->{items} }, #Category: Single Users { linktext => $linktext{$crstype}{'single'}, @@ -5416,12 +5436,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.', }, ); @@ -5447,7 +5467,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.', }, ); @@ -5484,11 +5504,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); @@ -5497,6 +5517,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'); @@ -5607,7 +5628,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) } } @@ -5654,6 +5675,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) { @@ -5663,8 +5704,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". @@ -5672,25 +5711,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}) { @@ -5700,7 +5785,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; @@ -5765,7 +5884,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 { @@ -5778,13 +5910,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, @@ -5794,13 +5935,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, @@ -5810,7 +5960,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 '') { @@ -5818,6 +5971,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". @@ -5827,24 +5989,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'; @@ -5863,7 +6030,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; @@ -5891,14 +6064,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 = ' '; @@ -5910,6 +6098,7 @@ ENDSCRIPT } else { $crslimit = ' '; $selflimit = ' '; + $nolimit = ' checked="checked" '; } $output .= '<table><tr><td><label>'. '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'. @@ -5929,42 +6118,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.'); @@ -5979,10 +6177,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'); @@ -6006,8 +6204,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'); @@ -6053,7 +6251,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 { @@ -6572,13 +6796,29 @@ sub user_search_result { } } if ($response ne '') { - $response = '<span class="LC_warning">'.$response.'</span>'; + $response = '<span class="LC_warning">'.$response.'</span><br />'; } if ($srch->{'srchin'} eq 'instd') { - my $instd_chk = &directorysrch_check($srch); + my $instd_chk = &instdirectorysrch_check($srch); if ($instd_chk ne 'ok') { - $response = '<span class="LC_warning">'.$instd_chk.'</span>'. - '<br />'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'<br /><br />'; + my $domd_chk = &domdirectorysrch_check($srch); + $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />'; + if ($domd_chk eq 'ok') { + $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.'); + } + $response .= '<br /><br />'; + } + } else { + unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) { + my $domd_chk = &domdirectorysrch_check($srch); + if ($domd_chk ne 'ok') { + my $instd_chk = &instdirectorysrch_check($srch); + $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />'; + if ($instd_chk eq 'ok') { + $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.'); + } + $response .= '<br /><br />'; + } } } if ($response ne '') { @@ -6742,7 +6982,8 @@ sub user_search_result { ($currstate,$response,$forcenewuser) = &build_search_response($context,$srch,%srch_results); } else { - my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'. + my $showdom = &display_domain_info($srch->{'srchdomain'}); + $response = '<span class="LC_warning">'. &mt('Institutional directory search is not available in domain: [_1]',$showdom). '</span><br />'. &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.'). @@ -6753,7 +6994,26 @@ sub user_search_result { return ($currstate,$response,$forcenewuser,\%srch_results); } -sub directorysrch_check { +sub domdirectorysrch_check { + my ($srch) = @_; + my $response; + my %dom_inst_srch = &Apache::lonnet::get_dom('configuration', + ['directorysrch'],$srch->{'srchdomain'}); + my $showdom = &display_domain_info($srch->{'srchdomain'}); + if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') { + if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') { + return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom); + } + if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) { + if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) { + return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom); + } + } + } + return 'ok'; +} + +sub instdirectorysrch_check { my ($srch) = @_; my $can_search = 0; my $response; @@ -7066,13 +7326,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); } } } @@ -7081,7 +7341,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); } } } @@ -7095,7 +7356,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(). @@ -7106,14 +7371,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>'; @@ -7190,8 +7455,9 @@ 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'".')" />'. @@ -7201,8 +7467,8 @@ sub course_level_dc { my $plrole=&Apache::lonnet::plaintext($role); $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.'</option>'; @@ -7221,7 +7487,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='' /> @@ -7237,19 +7503,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}; @@ -7258,15 +7528,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'} = '*'; @@ -7335,9 +7604,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+$/) { @@ -7346,7 +7615,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'} = ''; @@ -7358,13 +7628,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); @@ -7400,14 +7671,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.'); @@ -7437,11 +7708,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 = @@ -7478,7 +7748,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'); @@ -7488,7 +7758,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') { @@ -7500,24 +7770,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) { @@ -7548,13 +7818,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.')); @@ -7562,39 +7835,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