--- loncom/interface/loncreateuser.pm 2008/05/12 17:52:09 1.239 +++ loncom/interface/loncreateuser.pm 2008/08/27 21:55:32 1.261 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.239 2008/05/12 17:52:09 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.261 2008/08/27 21:55:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -967,7 +967,7 @@ sub display_existing_roles { if (defined($coursedata{'description'})) { $carea=$coursedata{'description'}. '
'.&mt('Domain').': '.$coursedom.(' 'x8). - &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom); + &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom); $sortkey.="\0".$coursedata{'description'}; $class=$coursedata{'type'}; } else { @@ -1396,10 +1396,12 @@ sub modify_login_block { } sub personal_data_display { - my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_; + my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_; my ($output,$showforceid,%userenv,%canmodify); my @userinfo = ('firstname','middlename','lastname','generation', 'permanentemail','id'); + my $rowcount = 0; + my $editable = 0; if (!$newuser) { # Get the users information %userenv = &Apache::lonnet::get('environment', @@ -1407,7 +1409,10 @@ sub personal_data_display { 'permanentemail','id'],$ccdomain,$ccuname); %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain, - \@userinfo); + \@userinfo,$rolesarray); + } elsif ($context eq 'selfcreate') { + %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo, + $inst_results,$rolesarray); } my %lt=&Apache::lonlocal::texthash( 'pd' => "Personal Data", @@ -1416,7 +1421,7 @@ sub personal_data_display { 'lastname' => "Last Name", 'generation' => "Generation", 'permanentemail' => "Permanent e-mail address", - 'id' => "ID/Student Number", + 'id' => "Student/Employee ID", 'lg' => "Login Data" ); my %textboxsize = ( @@ -1432,40 +1437,93 @@ sub personal_data_display { &Apache::lonhtmlcommon::start_pick_box(); foreach my $item (@userinfo) { my $rowtitle = $lt{$item}; + my $hiderow = 0; if ($item eq 'generation') { $rowtitle = $genhelp.$rowtitle; } - $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n"; + my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n"; if ($newuser) { if (ref($inst_results) eq 'HASH') { if ($inst_results->{$item} ne '') { - $output .= ''.$inst_results->{$item}; + $row .= ''.$inst_results->{$item}; } else { - $output .= ''; + if ($context eq 'selfcreate') { + if ($canmodify{$item}) { + $row .= ''; + $editable ++; + } else { + $hiderow = 1; + } + } else { + $row .= ''; + } } } else { - $output .= ''; + if ($context eq 'selfcreate') { + if ($canmodify{$item}) { + $row .= ''; + $editable ++; + } else { + $hiderow = 1; + } + } else { + $row .= ''; + } } } else { if ($canmodify{$item}) { - $output .= ''; + $row .= ''; } else { - $output .= $userenv{$item}; + $row .= $userenv{$item}; } if ($item eq 'id') { $showforceid = $canmodify{$item}; } } - $output .= &Apache::lonhtmlcommon::row_closure(1); + $row .= &Apache::lonhtmlcommon::row_closure(1); + if (!$hiderow) { + $output .= $row; + $rowcount ++; + } } $output .= &Apache::lonhtmlcommon::end_pick_box(); if (wantarray) { - return ($output,$showforceid); + if ($context eq 'selfcreate') { + return($output,$rowcount,$editable); + } else { + return ($output,$showforceid); + } } else { return $output; } } +sub selfcreate_canmodify { + my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_; + if (ref($inst_results) eq 'HASH') { + my @inststatuses = &get_inststatuses($inst_results); + if (@inststatuses == 0) { + @inststatuses = ('default'); + } + $rolesarray = \@inststatuses; + } + my %canmodify = + &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo, + $rolesarray); + return %canmodify; +} + +sub get_inststatuses { + my ($insthashref) = @_; + my @inststatuses = (); + if (ref($insthashref) eq 'HASH') { + if (ref($insthashref->{'inststatus'}) eq 'ARRAY') { + @inststatuses = @{$insthashref->{'inststatus'}}; + } + } + return @inststatuses; +} + # ================================================================= Phase Three sub update_user_data { my ($r,$context) = @_; @@ -1789,7 +1847,7 @@ sub update_user_data { $env{'form.c'.$item} = $userenv{$item}; } } - # Check to see if we can change the ID/student number + # Check to see if we can change the Student/Employee ID my $forceid = $env{'form.forceid'}; my $recurseid = $env{'form.recurseid'}; my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules); @@ -1800,7 +1858,10 @@ sub update_user_data { (!$forceid)) { if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) { $env{'form.cid'} = $userenv{'id'}; - $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'
'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'
'."\n"; + $no_forceid_alert = &mt('New Student/Employee ID does not match existing ID for this user.') + .'
' + .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.") + .'
'."\n"; } } if ($env{'form.cid'} ne $userenv{'id'}) { @@ -1914,7 +1975,7 @@ sub update_user_data { 'mddl' => "middle", 'lst' => "last", 'gen' => "generation", - 'id' => "ID/Student number", + 'id' => "Student/Employee ID", 'mail' => "permanent e-mail", 'disk' => "disk space allocated to portfolio files", 'prvs' => "Previous", @@ -1997,7 +2058,7 @@ END # They did not want to change the users name or quota but we can # still tell them what the name and quota are my %lt=&Apache::lonlocal::texthash( - 'id' => "ID/Student number", + 'id' => "Student/Employee ID", 'mail' => "Permanent e-mail", 'disk' => "Disk space allocated to user's portfolio files", ); @@ -2040,8 +2101,10 @@ END $r->print(''.$rolestr.'
'. &mt('Contact your helpdesk for more information.',"javascript:helpMenu('display')").'
'); } - $r->print($no_forceid_alert. - &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)); + $r->print('' + .$no_forceid_alert + .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules) + .''); } if ($env{'form.action'} eq 'singlestudent') { &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context); @@ -2069,7 +2132,10 @@ END if ($env{'form.popup'}) { $r->print('

'.&mt('Close window').'

'); } else { - $r->print('

'.&mt('Modify this user: ([_1])',$userinfo).''.(' 'x5).''.&mt('Create/Modify Another User').'

'); + $r->print('

' + .&mt('Modify this user: [_1]',''.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')').'' + .(' 'x5).'' + .&mt('Create/Modify Another User').'

'); } } $r->print(&Apache::loncommon::end_page()); @@ -2146,7 +2212,7 @@ sub update_roles { $rolename,$rnam,$rdom,$url).': '. &Apache::lonnet::assigncustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now, - 0,1).'
'); + 0,1,$context).'
'); if (!grep(/^cr$/,@rolechanges)) { push(@rolechanges,'cr'); } @@ -2193,7 +2259,7 @@ sub update_roles { my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4); my $result = &Apache::lonnet::assigncustomrole( $env{'form.ccdomain'}, $env{'form.ccuname'}, - $url,$rdom,$rnam,$rolename,0,$now); + $url,$rdom,$rnam,$rolename,0,$now,undef,$context); $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]', $rolename,$rnam,$rdom,$url,$result).'
'); if (!grep(/^cr$/,@rolechanges)) { @@ -2220,7 +2286,7 @@ sub update_roles { my %sections = (); my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5); if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end)); + $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context)); } else { my %curr_groups = &Apache::longroup::coursegroups($one,$two); @@ -2231,7 +2297,7 @@ sub update_roles { next; } my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end)); + $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context)); } } if (!grep(/^cr$/,@rolechanges)) { @@ -2253,7 +2319,7 @@ sub update_roles { my %sections = (); my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three); if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context)); } else { my %curr_groups = &Apache::longroup::coursegroups($one,$two); @@ -2267,13 +2333,13 @@ sub update_roles { next; } my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context)); } else { $emptysec = 1; } } if ($emptysec) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context)); } } if (!grep(/^\Q$three\E$/,@rolechanges)) { @@ -2295,19 +2361,19 @@ sub update_roles { my %sections = (); my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two); if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); + $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) { if ($sec ne '') { my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context)); } else { $emptysec = 1; } } if ($emptysec) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context)); } } if (!grep(/^\Q$two\E$/,@rolechanges)) { @@ -2670,7 +2736,7 @@ sub make_button_code { } # ---------------------------------------------------------- Call to definerole sub set_custom_role { - my ($r) = @_; + my ($r,$context) = @_; my $rolename=$env{'form.rolename'}; $rolename=~s/[^A-Za-z0-9]//gs; if (!$rolename) { @@ -2745,7 +2811,7 @@ sub set_custom_role { $url, $env{'user.domain'}, $env{'user.name'}, - $rolename)); + $rolename,undef,undef,undef,$context)); } $r->print('

'.&mt('Create or edit another custom role').'

'); $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'
'); @@ -2889,7 +2955,7 @@ sub handler { } } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) { if ($env{'form.phase'} eq 'set_custom_roles') { - &set_custom_role($r); + &set_custom_role($r,$context); } else { &custom_role_editor($r); } @@ -2981,7 +3047,7 @@ sub handler { if (!exists($env{'form.state'})) { $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment', 'Course_Self_Enrollment')); - + $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); &print_selfenroll_menu($r,$context,$permission); } elsif ($env{'form.state'} eq 'done') { &Apache::lonhtmlcommon::add_breadcrumb @@ -2989,7 +3055,8 @@ sub handler { text=>"Result"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result', 'Course_Self_Enrollment')); - &update_selfenroll_config($r,$context); + $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); + &update_selfenroll_config($r,$context,$permission); } $r->print(&Apache::loncommon::end_page()); } elsif ($env{'form.action'} eq 'changelogs') { @@ -3104,7 +3171,7 @@ sub print_main_menu { }); if (!exists($permission->{'cusr_section'})) { push(@courselinks, - { text => 'Automated Student Enrollment Manager', + { text => 'Automated Enrollment Manager', help => 'Course_Automated_Enrollment', permission => (&Apache::lonnet::auto_run($cnum,$cdom) && $permission->{'cusr'}), @@ -3122,16 +3189,16 @@ sub print_main_menu { permission => $permission->{'grp_manage'}, url => '/adm/coursegroups?refpage=cusr', }, - { text => 'View Log-in History', - help => 'Course_User_Logins', - action => 'logins', - permission => $permission->{'cusr'}, - }, { text => 'View Change Logs', help => 'Course_User_Logs', action => 'changelogs', permission => $permission->{'cusr'}, - }); + },); +# { text => 'View Log-in History', +# help => 'Course_User_Logins', +# action => 'logins', +# permission => $permission->{'cusr'}, +# }); push(@menu,@courselinks); } my $menu_html = ''; @@ -3174,12 +3241,203 @@ sub print_selfenroll_menu { my $groupslist = &Apache::lonuserutils::get_groupslist(); my $setsec_js = &Apache::lonuserutils::setsections_javascript($formname,$groupslist); + my %alerts = &Apache::lonlocal::texthash( + acto => 'Activation of self-enrollment was selected for the following domain(s)', + butn => 'but no user types have been checked.', + wilf => "Please uncheck 'activate' or check at least one type.", + ); + my $selfenroll_js = <<"ENDSCRIPT"; +function update_types(caller,num) { + var delidx = getIndexByName('selfenroll_delete'); + var actidx = getIndexByName('selfenroll_activate'); + if (caller == 'selfenroll_all') { + var selall; + for (var i=0; i 0) { + var msg = "$alerts{'acto'}\\n"; + var loopend = needaction.length -1; + if (loopend > 0) { + for (var m=0; m'."\n". - '

'.$lt->{'selfenroll'}.'

'."\n". - '
'."\n". - &Apache::lonhtmlcommon::start_pick_box(); + '

'.$lt->{'selfenroll'}.'

'."\n"; + my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum); + if (ref($visactions) eq 'HASH') { + if ($visible) { + $output .= '

'.$visactions->{'vis'}.'

'; + } else { + $output .= $visactions->{'miss'}.'
'.$visactions->{'yous'}. + '

'.$visactions->{'gen'}.'
'.$visactions->{'coca'}; + if (ref($vismsgs) eq 'ARRAY') { + $output .= '
'.$visactions->{'make'}.'

    '; + foreach my $item (@{$vismsgs}) { + $output .= '
  • '.$visactions->{$item}.'
  • '; + } + $output .= '
'; + } + $output .= '

'; + } + } + $output .= ''."\n". + &Apache::lonhtmlcommon::start_pick_box(); if (ref($row) eq 'ARRAY') { foreach my $item (@{$row}) { my $title = $item; @@ -3191,7 +3449,68 @@ sub print_selfenroll_menu { 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n"; if ($item eq 'types') { my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'}; - $output .= ''; + my $showdomdesc = 1; + my $includeempty = 1; + my $num = 0; + $output .= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row() + .''. + '  '.&mt('No').''. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(). + &mt('Or').'
'. + &Apache::loncommon::start_data_table(); + my %currdoms; + if ($curr_types eq '') { + $output .= &new_selfenroll_dom_row($cdom,'0'); + } elsif ($curr_types ne '*') { + my @entries = split(/;/,$curr_types); + if (@entries > 0) { + foreach my $entry (@entries) { + my ($currdom,$typestr) = split(/:/,$entry); + $currdoms{$currdom} = 1; + my $domdesc = &Apache::lonnet::domain($currdom); + my @currinsttypes = split(',',$typestr); + $output .= &Apache::loncommon::start_data_table_row() + .''.&mt('Domain:').'' + .' '.$domdesc.' ('.$currdom.')' + .'
' + .''; + $output .= '  '.&mt('User types:').'
' + .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'' + .&Apache::loncommon::end_data_table_row(); + $num ++; + } + } + } + my $add_domtitle = &mt('Users in additional domain:'); + if ($curr_types eq '*') { + $add_domtitle = &mt('Users in specific domain:'); + } elsif ($curr_types eq '') { + $add_domtitle = &mt('Users in other domain:'); + } + $output .= &Apache::loncommon::start_data_table_row() + .''.$add_domtitle.'
' + .&Apache::loncommon::select_dom_form('','selfenroll_newdom', + $includeempty,$showdomdesc) + .'' + .''.&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table(); } elsif ($item eq 'registered') { my ($regon,$regoff); if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) { @@ -3202,10 +3521,10 @@ sub print_selfenroll_menu { $regoff = ' checked="checked" '; } $output .= '  '; + ''. + &mt('Yes').'  '; } 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'}; @@ -3240,8 +3559,6 @@ sub print_selfenroll_menu { $output .= &selfenroll_date_forms($startform,$endform); } elsif ($item eq 'section') { my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'}; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'},'.num'}; my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); my $newsecval; if ($currsec ne 'none' && $currsec ne '') { @@ -3265,20 +3582,224 @@ sub print_selfenroll_menu { } } $output .= &Apache::lonhtmlcommon::end_pick_box(). - '
'; + '
' + .''; $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 currently appears in the Course 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 does not currently appear in the Course 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 changes", 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]Set course environment[_2] to change the "Exclude from course catalog" setting.','"','"'); + $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"'); + $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"','"'); + if (ref($domconf{'coursecategories'}) eq 'HASH') { + if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') { + $settable{'togglecats'} = 1; + } + if ($domconf{'coursecategories'}{'categorize'} eq 'crs') { + $settable{'categorize'} = 1; + } + $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.'); + } elsif ($settable{'togglecats'}) { + $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.'); + } elsif ($settable{'categorize'}) { + $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.'); + } else { + $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.'); + } + + my %currsettings = + &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'], + $cdom,$cnum); + my $visible = 0; + if ($currsettings{'internal.coursecode'} ne '') { + if (ref($domconf{'coursecategories'}) eq 'HASH') { + $cathash = $domconf{'coursecategories'}{'cats'}; + if (ref($cathash) eq 'HASH') { + if ($cathash->{'instcode::0'} eq '') { + push(@vismsgs,'dc_addinst'); + } else { + $visible = 1; + } + } else { + $visible = 1; + } + } else { + $visible = 1; + } + } else { + if (ref($cathash) eq 'HASH') { + if ($cathash->{'instcode::0'} ne '') { + push(@vismsgs,'dc_instcode'); + } + } else { + push(@vismsgs,'dc_instcode'); + } + } + if ($currsettings{'categories'} ne '') { + my $cathash; + if (ref($domconf{'coursecategories'}) eq 'HASH') { + $cathash = $domconf{'coursecategories'}{'cats'}; + if (ref($cathash) eq 'HASH') { + if (keys(%{$cathash}) == 0) { + push(@vismsgs,'dc_catalog'); + } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) { + push(@vismsgs,'dc_categories'); + } else { + my @currcategories = split('&',$currsettings{'categories'}); + my $matched = 0; + foreach my $cat (@currcategories) { + if ($cathash->{$cat} ne '') { + $visible = 1; + $matched = 1; + last; + } + } + if (!$matched) { + if ($settable{'categorize'}) { + push(@vismsgs,'chgcat'); + } else { + push(@vismsgs,'dc_chgcat'); + } + } + } + } + } + } else { + if (ref($cathash) eq 'HASH') { + if ((keys(%{$cathash}) > 1) || + (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) { + if ($settable{'categorize'}) { + push(@vismsgs,'addcat'); + } else { + push(@vismsgs,'dc_addcat'); + } + } + } + } + if ($currsettings{'hidefromcat'} eq 'yes') { + $visible = 0; + if ($settable{'togglecats'}) { + unshift(@vismsgs,'unhide'); + } else { + unshift(@vismsgs,'dc_unhide') + } + } + return ($visible,$cansetvis,\@vismsgs,\%visactions); +} + +sub new_selfenroll_dom_row { + my ($newdom,$num) = @_; + my $domdesc = &Apache::lonnet::domain($newdom); + my $output; + if ($domdesc ne '') { + $output .= &Apache::loncommon::start_data_table_row() + .''.&mt('Domain:').' '.$domdesc + .' ('.$newdom.')
' + .''; + my @currinsttypes; + $output .= ''.&mt('User types:').'
' + .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'' + .&Apache::loncommon::end_data_table_row(); + } + return $output; +} + +sub selfenroll_inst_types { + my ($num,$currdom,$currinsttypes) = @_; + my $output; + my $numinrow = 4; + my $count = 0; + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom); + my $othervalue = 'any'; + if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) { + if (keys(%{$usertypes}) > 0) { + $othervalue = 'other'; + } + $output .= ''; + foreach my $type (@{$types}) { + if (($count > 0) && ($count%$numinrow == 0)) { + $output .= ''; + } + if (defined($usertypes->{$type})) { + my $esc_type = &escape($type); + $output .= ''; + } + $count ++; + } + if (($count > 0) && ($count%$numinrow == 0)) { + $output .= ''; + } + $output .= '
'; + } + return $output; +} + sub selfenroll_date_forms { my ($startform,$endform) = @_; my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title(&mt('Starts'), + &Apache::lonhtmlcommon::row_title(&mt('Start date'), 'LC_oddrow_value')."\n". $startform."\n". &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::row_title(&mt('Ends'), + &Apache::lonhtmlcommon::row_title(&mt('End date'), 'LC_oddrow_value')."\n". $endform."\n". &Apache::lonhtmlcommon::row_closure(1). @@ -3327,8 +3848,9 @@ sub print_userchangelogs_display { $curr{$key} = $defaults{$key}; } } - my (%whodunit,%changed); - $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr)); + my (%whodunit,%changed,$version); + ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/); + $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version)); my $showntablehdr = 0; my $tablehdr = &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). @@ -3337,7 +3859,7 @@ sub print_userchangelogs_display { &mt('Context').''.&mt('Start').''.&mt('End').''. &Apache::loncommon::end_data_table_header_row(); my ($minshown,$maxshown); - my $minshown = 1; + $minshown = 1; my $count = 0; if ($curr{'show'} ne &mt('all')) { $maxshown = $curr{'page'} * $curr{'show'}; @@ -3445,7 +3967,7 @@ ENDSCRIPT } sub role_display_filter { - my ($formname,$cdom,$cnum,$curr) = @_; + my ($formname,$cdom,$cnum,$curr,$version) = @_; my $context = 'course'; my $nolink = 1; my $output = '
'. @@ -3496,9 +4018,14 @@ sub role_display_filter { next if (!&Apache::lonnet::auto_run($cnum,$cdom)); } $output .= ''."\n"; - } + } $output .= '  


'; + &mt('Update Display').'" />'. + ''. + &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.'); + if ($version) { + $output .= ' '.&mt('This server is version [_3].','','',$version); } + $output .= '

'; return $output; } @@ -3547,7 +4074,13 @@ sub user_search_result { if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') || ($srch->{'srchin'} eq 'alc')) { if ($srch->{'srchby'} eq 'uname') { - if ($srch->{'srchterm'} !~ /^$match_username$/) { + my $unamecheck = $srch->{'srchterm'}; + if ($srch->{'srchtype'} eq 'contains') { + if ($unamecheck !~ /^\w/) { + $unamecheck = 'a'.$unamecheck; + } + } + if ($unamecheck !~ /^$match_username$/) { $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); } } @@ -4138,13 +4671,13 @@ ENDTIMEENTRY } sub update_selfenroll_config { - my ($r,$context) = @_; + my ($r,$context,$permission) = @_; my ($row,$lt) = &get_selfenroll_titles(); - my $groupslist = &Apache::lonuserutils::get_groupslist(); + my %curr_groups = &Apache::longroup::coursegroups(); my (%changes,%warning); my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - $r->print('

'.$lt->{'selfenroll'}.'

'."\n"); + my $curr_types; if (ref($row) eq 'ARRAY') { foreach my $item (@{$row}) { if ($item eq 'enroll_dates') { @@ -4165,13 +4698,79 @@ sub update_selfenroll_config { $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type}; } } + } elsif ($item eq 'types') { + $curr_types = + $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; + if ($env{'form.selfenroll_all'}) { + if ($curr_types ne '*') { + $changes{'internal.selfenroll_types'} = '*'; + } else { + next; + } + } else { + my %currdoms; + my @entries = split(/;/,$curr_types); + my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete'); + my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate'); + my $newnum = 0; + my @latesttypes; + foreach my $num (@activations) { + my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num); + if (@types > 0) { + @types = sort(@types); + my $typestr = join(',',@types); + my $typedom = $env{'form.selfenroll_dom_'.$num}; + $latesttypes[$newnum] = $typedom.':'.$typestr; + $currdoms{$typedom} = 1; + $newnum ++; + } + } + for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) { + my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j); + if (@types > 0) { + @types = sort(@types); + my $typestr = join(',',@types); + my $typedom = $env{'form.selfenroll_dom_'.$j}; + $latesttypes[$newnum] = $typedom.':'.$typestr; + $currdoms{$typedom} = 1; + $newnum ++; + } + } + } + if ($env{'form.selfenroll_newdom'} ne '') { + my $typedom = $env{'form.selfenroll_newdom'}; + if ((!defined($currdoms{$typedom})) && + (&Apache::lonnet::domain($typedom) ne '')) { + my $typestr; + my ($othertitle,$usertypes,$types) = + &Apache::loncommon::sorted_inst_types($typedom); + my $othervalue = 'any'; + if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) { + if (@{$types} > 0) { + my @esc_types = map { &escape($_); } @{$types}; + $othervalue = 'other'; + $typestr = join(',',(@esc_types,$othervalue)); + } + $typestr = $othervalue; + } else { + $typestr = $othervalue; + } + $latesttypes[$newnum] = $typedom.':'.$typestr; + $newnum ++ ; + } + } + my $selfenroll_types = join(';',@latesttypes); + if ($selfenroll_types ne $curr_types) { + $changes{'internal.selfenroll_types'} = $selfenroll_types; + } + } } else { my $curr_val = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; my $newval = $env{'form.selfenroll_'.$item}; if ($item eq 'section') { $newval = $env{'form.sections'}; - if (grep(/^\Q$newval\E$/,keys(%{$groupslist}))) { + if (defined($curr_groups{$newval})) { $newval = $curr_val; $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'
'.&mt('Group names and section names must be distinct'); } elsif ($newval eq 'all') { @@ -4185,7 +4784,7 @@ sub update_selfenroll_config { if ($newval ne $curr_val) { $changes{'internal.selfenroll_'.$item} = $newval; } - } + } } if (keys(%warning) > 0) { foreach my $item (@{$row}) { @@ -4225,7 +4824,7 @@ sub update_selfenroll_config { foreach my $type ('start','end') { if (exists($changes{'internal.selfenroll_'.$type.'_date'})) { my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'}); - $r->print('
  • '.&mt('[_1]: [_2] set to "[_3]".', + $r->print('
  • '.&mt('[_1]: "[_2]" set to "[_3]".', $title,$type,$newdate).'
  • '); } } @@ -4233,14 +4832,27 @@ sub update_selfenroll_config { foreach my $type ('start','end') { if (exists($changes{'internal.selfenroll_'.$type.'_access'})) { my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'}); - $r->print('
  • '.&mt('[_1]: [_2] set to "[_3]".', + $r->print('
  • '.&mt('[_1]: "[_2]" set to "[_3]".', $title,$type,$newdate).'
  • '); } } } else { if (exists($changes{'internal.selfenroll_'.$item})) { - $r->print('
  • '.&mt('[_1] set to "[_2]".',$title, - $changes{'internal.selfenroll_'.$item}).'
  • '."\n"); + my $newval = $changes{'internal.selfenroll_'.$item}; + if ($item eq 'types') { + if ($newval eq '') { + $newval = &mt('None'); + } elsif ($newval eq '*') { + $newval = &mt('Any user in any domain'); + } + } elsif ($item eq 'registered') { + if ($newval eq '1') { + $newval = &mt('Yes'); + } elsif ($newval eq '0') { + $newval = &mt('No'); + } + } + $r->print('
  • '.&mt('"[_1]" set to "[_2]".',$title,$newval).'
  • '."\n"); } } } @@ -4254,23 +4866,37 @@ sub update_selfenroll_config { $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'
    '.&mt('The error was: [_1].',$putresult)); } } else { - $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.')); + $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.')); } } else { - $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.')); + $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) { + $r->print('
    '.$visactions->{'miss'}.'
    '.$visactions->{'yous'}. + '
    '); + if (ref($vismsgs) eq 'ARRAY') { + $r->print('
    '.$visactions->{'take'}.'
      '); + foreach my $item (@{$vismsgs}) { + $r->print('
    • '.$visactions->{$item}.'
    • '); + } + $r->print('
    '); + } + $r->print($cansetvis); + } + } return; } sub get_selfenroll_titles { my @row = ('types','registered','enroll_dates','access_dates','section'); my %lt = &Apache::lonlocal::texthash ( - selfenroll => 'Self-enrollment with a student role', types => 'Users allowed to self-enroll in this course', - registered => 'Restrict self-enrollment to registered students?', + registered => 'Restrict self-enrollment to students officially registered for the course', enroll_dates => 'Dates self-enrollment available', - access_dates => 'Access dates for self-enrolled users', - section => 'Section', + access_dates => 'Course access dates assigned to self-enrolling users', + section => 'Section assigned to self-enrolling users', ); return (\@row,\%lt); }