--- loncom/interface/lonrequestcourse.pm 2010/07/07 17:27:41 1.54 +++ loncom/interface/lonrequestcourse.pm 2011/03/06 21:17:15 1.63 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.54 2010/07/07 17:27:41 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.63 2011/03/06 21:17:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -556,7 +556,6 @@ sub form_elements { } if (&Apache::lonnet::auto_run('',$dom)) { my %extras = ( - sectotal => 'hidden', enrollstart_month => 'selectbox', enrollstart_hour => 'selectbox', enrollend_month => 'selectbox', @@ -572,12 +571,30 @@ sub form_elements { addcrosslist => 'checkbox', autoadds => 'radio', autodrops => 'radio', - ); - if ($env{'form.sectotal'} > 0) { - for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - $extras{'sec_'.$i} = 'radio'; - $extras{'secnum_'.$i} = 'text'; - $extras{'loncapasec_'.$i} = 'text'; + ); + my ($instcode,$titlescount) = &get_instcode($dom); + if ($instcode) { + my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode); + if (@sections) { + $extras{'sectotal'} = 'hidden'; + if ($env{'form.sectotal'} > 0) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + $extras{'sec_'.$i} = 'radio'; + $extras{'secnum_'.$i} = 'text'; + $extras{'loncapasec_'.$i} = 'text'; + } + } + } else { + $extras{'addsection'} = 'checkbox'; + my $sectotal = $env{'form.sectotal'}; + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $extras{'sec_'.$i} = 'checkbox'; + $extras{'secnum_'.$i} = 'text', + $extras{'loncapasec_'.$i} = 'text', + } } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -587,7 +604,6 @@ sub form_elements { if (!$crosslisttotal) { $crosslisttotal = 1; } - for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) { if ($numtitles) { $extras{'crosslist_'.$i.'_'.$lastitem} = 'text'; @@ -1322,16 +1338,38 @@ sub print_request_form { } if ($skipuser) { push(@disallowed,$i); - $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain',''.$personname.':'.$persondom.''); + $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain',''.$personname.':'.$persondom.''); next; } } - if (&get_cancreate_status($persondom,$personname,$dom)) { - my ($allowed,$msg) = + my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = &check_newuser_rules($persondom,$personname, \%alerts,\%rulematch,\%inst_results, \%curr_rules,\%got_rules); if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb/) && ($authparam eq ''))) { + push(@disallowed,$i); + $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.',''.$personname.':'.$persondom.''); + next; + } if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') { if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') { $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'}; @@ -1446,7 +1484,7 @@ sub print_request_form { } } if ($state eq 'enrollment') { - push(@excluded,'crosslisttotal'); + push(@excluded,('sectotal','crosslisttotal')); } $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, @@ -1454,13 +1492,13 @@ sub print_request_form { return; } -sub get_cancreate_status { - my ($persondom,$personname,$dom) = @_; +sub get_usertype { + my ($persondom,$personname,$curr_rules,$got_rules) = @_; my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($persondom,'username'); my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname, - $rules); - return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype); + $rules,$curr_rules,$got_rules); + return $usertype; } sub check_newuser_rules { @@ -1468,7 +1506,7 @@ sub check_newuser_rules { $got_rules) = @_; my $allowed = 1; my $newuser = 1; - my ($checkhash,$userchkmsg); + my ($checkhash,$userchkmsg,$authtype,$authparam); my $checks = { 'username' => 1 }; $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser }; &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch, @@ -1490,7 +1528,22 @@ sub check_newuser_rules { } } } - return ($allowed,$userchkmsg); + if ($allowed) { + if (ref($rulematch) eq 'HASH') { + if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') { + my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'}; + my ($rules,$ruleorder) = + &Apache::lonnet::inst_userrules($persondom,'username'); + if (ref($rules) eq 'HASH') { + if (ref($rules->{$matchedrule}) eq 'HASH') { + $authtype = $rules->{$matchedrule}{'authtype'}; + $authparam = $rules->{$matchedrule}{'authparm'}; + } + } + } + } + } + return ($allowed,$userchkmsg,$authtype,$authparam); } sub get_excluded_elements { @@ -1540,7 +1593,29 @@ sub print_enrollment_menu { if (&Apache::lonnet::auto_run('',$dom)) { $output = &show_invalid_crosslists($invalidcrosslist); my ($section_form,$crosslist_form); - $section_form = &inst_section_selector($dom,$instcode); + if ($instcode ne '') { + $section_form = &inst_section_selector($dom,$instcode); + if ($section_form eq '') { + my $sectotal = $env{'form.sectotal'}; + if (!$sectotal) { + $sectotal = 1; + } + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $section_form .= §ions_form($dom,$instcode,$i); + } + if ($section_form) { + $section_form .= + &Apache::lonhtmlcommon::row_title(&mt('Add another')). + ''. + ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); + } + } + } if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). @@ -1567,7 +1642,7 @@ sub print_enrollment_menu { ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}. "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); $sections .= &Apache::lonhtmlcommon::row_headline. - '

'.&mt('Crosslisted courses for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } @@ -2534,8 +2609,8 @@ sub print_review { if (($env{'form.cloning'}) && ($env{'form.clonecrs'} =~ /^$match_name$/) && ($env{'form.clonedom'} =~ /^$match_domain$/)) { - my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, + my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, + $udom,$env{'form.clonecrs'},$env{'form.clonedom'}, $env{'form.crstype'}); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, @@ -2825,7 +2900,6 @@ sub coursecode_form { ); my %helpitem = ( instcode => 'Course_Request_Category', - crosslist => 'Course_Request_Crosslist', ); if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && (ref($cat_order))) { @@ -2842,7 +2916,11 @@ sub coursecode_form { my $lastitem = pop(@{$codetitles}); my $lastinput = ''; if (@{$codetitles} > 0) { - $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}). + my $helplink; + if (defined($helpitem{$context})) { + $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' '; + } + $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}). ''; if ($context eq 'crosslist') { $output .= '
'.&mt('Include?').'
'. @@ -2907,6 +2985,26 @@ sub coursecode_form { return $output; } +sub sections_form { + my ($dom,$instcode,$num) = @_; + my $rowtitle; + if ($instcode eq '') { + $rowtitle = &mt('Sections'); + } else { + $rowtitle = &mt('Sections of [_1]',$instcode); + } + return &Apache::lonhtmlcommon::row_title($rowtitle). + '
'. + ''.&mt('Include?'). + ''. + ''.&mt('Institutional section').'
'. + ''. + '
'.&mt('LON-CAPA section').'
'. + ''. + '
'. + &Apache::lonhtmlcommon::row_closure(1); +} + sub get_course_dom { my $codedom = &Apache::lonnet::default_login_domain(); if ($env{'form.showdom'} ne '') { @@ -3036,6 +3134,10 @@ sub print_request_outcome { push(@instsections,$sec); } $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i}; + $sections{$i}{'loncapa'} =~ s/\W//g; + if ($sections{$i}{'loncapa'} eq 'none') { + $sections{$i}{'loncapa'} = ''; + } } } } @@ -3061,6 +3163,7 @@ sub print_request_outcome { $enrollstart = ''; $enrollend = ''; } + my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped); for (my $i=0; $i<$env{'form.persontotal'}; $i++) { my $uname = $env{'form.person_'.$i.'_uname'}; my $udom = $env{'form.person_'.$i.'_dom'}; @@ -3072,6 +3175,56 @@ sub print_request_outcome { lastname => $env{'form.person_'.$i.'_lastname'}, emailaddr => $env{'form.person_'.$i.'_emailaddr'}, }; + if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') { + my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = + &check_newuser_rules($udom,$uname,\%alerts,\%rulematch, + \%inst_results,\%curr_rules,\%got_rules); + if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($udom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } else { + if ($authtype eq 'loc') { + $authtype = 'localauth'; + } elsif ($authtype eq 'int') { + $authtype = 'internal'; + } + if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) || + ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) { + $skipped{$uname.':'.$udom} = 1; + next; + } else { + $personnel{$uname.':'.$udom}{'authtype'} = $authtype; + $personnel{$uname.':'.$udom}{'autharg'} = $authparam; + } + } else { + $skipped{$uname.':'.$udom} = 1; + next; + } + } else { + $skipped{$uname.':'.$udom} = 1; + next; + } + } } my $role = $env{'form.person_'.$i.'_role'}; unless ($role eq '') { @@ -3117,6 +3270,11 @@ sub print_request_outcome { push(@baduname,$uname.':'.$udom); } } + if (keys(%skipped)) { + foreach my $key (keys(%skipped)) { + delete($personnel{$key}); + } + } my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend'); my $autodrops = 0; if ($env{'form.autodrops'}) { @@ -3124,10 +3282,7 @@ sub print_request_outcome { } my $autoadds = 0; if ($env{'form.autoadds'}) { - $autodrops = $env{'form.autoadds'}; - } - if ($env{'form.autoadds'}) { - $autodrops = $env{'form.autoadds'}; + $autoadds = $env{'form.autoadds'}; } my $instcode = ''; if (exists($env{'form.instcode'})) { @@ -3334,7 +3489,7 @@ sub print_request_outcome { } ($storeresult,my $updateresult) = &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom, - $cnum,$reqstatus,'request'); + $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'}); if ($modified && $queued && $storeresult eq 'ok') { if ($crstype eq 'community') { $output .= '

'.&mt('Your community request has been updated').'

'; @@ -3589,18 +3744,23 @@ sub retrieve_settings { } $env{'form.clonecrs'} = $reqinfo{'clonecrs'}; $env{'form.clonedom'} = $reqinfo{'clonedom'}; + if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) { + $env{'form.cloning'} = 1; + } $env{'form.datemode'} = $reqinfo{'datemode'}; $env{'form.dateshift'} = $reqinfo{'dateshift'}; - if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) { - $env{'form.sectotal'} = $reqinfo{'sectotal'}; - $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'}; - $env{'form.autoadds'} = $reqinfo{'autoadds'}; - $env{'form.autdrops'} = $reqinfo{'autodrops'}; - $env{'form.instcode'} = $reqinfo{'instcode'}; - my $crscode = { - $cnum => $reqinfo{'instcode'}, - }; - &extract_instcode($dom,'instcode',$crscode,$cnum); + if ($reqinfo{'crstype'} eq 'official') { + $env{'form.autoadds'} = $reqinfo{'autoadds'}; + $env{'form.autodrops'} = $reqinfo{'autodrops'}; + if ($reqinfo{'instcode'} ne '') { + $env{'form.sectotal'} = $reqinfo{'sectotal'}; + $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'}; + $env{'form.instcode'} = $reqinfo{'instcode'}; + my $crscode = { + $cnum => $reqinfo{'instcode'}, + }; + &extract_instcode($dom,'instcode',$crscode,$cnum); + } } my @currsec; if (ref($reqinfo{'sections'}) eq 'HASH') {