--- loncom/interface/lonrequestcourse.pm 2009/08/18 01:41:37 1.16 +++ loncom/interface/lonrequestcourse.pm 2009/08/21 13:18:46 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.16 2009/08/18 01:41:37 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.20 2009/08/21 13:18:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -116,13 +116,11 @@ use LONCAPA qw(:DEFAULT :match); sub handler { my ($r) = @_; + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; if ($r->header_only) { - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; return OK; } - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); @@ -159,9 +157,10 @@ sub handler { $states{'view'} = ['pick_request','details','cancel','removal']; $states{'log'} = ['filter','display']; $states{'new'} = ['courseinfo','enrollment','personnel','review','process']; + if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) { unless ($env{'form.state'} eq 'crstype') { - unshift (@{$states{'new'}},'codepick'); + unshift(@{$states{'new'}},'codepick'); } } @@ -429,6 +428,8 @@ sub check_can_request { my ($dom,$can_request) = @_; my $canreq = 0; my ($types,$typename) = &course_types(); + my @options = ('approval','validate','autolimit'); + my $optregex = join('|',@options); if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) { foreach my $type (@{$types}) { if (&Apache::lonnet::usertools_access($env{'user.name'}, @@ -444,7 +445,7 @@ sub check_can_request { if (@curr > 0) { $canreq ++; unless ($dom eq $env{'user.domain'}) { - if (grep(/^\Q$dom\E$/,@curr)) { + if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) { $can_request->{$type} = 1; } } @@ -775,7 +776,7 @@ sub print_request_form { } if ($instcode ne '') { $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode); - if ($code_chk eq 'ok') { + if ($code_chk eq 'valid') { $message = '
'. &mt('The chosen course category [_1] is valid.',''. $instcode.'').'
'; @@ -809,12 +810,19 @@ sub print_request_form { $r->print('
'.&Apache::lonhtmlcommon::start_pick_box().$codepicker. &Apache::lonhtmlcommon::end_pick_box().'
'); } else { + $next = $states->{$action}[$page+2]; $r->print(&courseinfo_form($dom,$formname,$crstype,$next)); } } else { + if ($crstype eq 'official') { + $next = $states->{$action}[$page+2]; + } $r->print(&courseinfo_form($dom,$formname,$crstype,$next)); } } elsif ($prev eq 'codepick') { + if ($env{'form.instcode'} eq '') { + $prev = $states->{$action}[$page-2]; + } $r->print(&courseinfo_form($dom,$formname,$crstype,$next)); } elsif ($state eq 'enrollment') { if ($crstype eq 'official') { @@ -1464,9 +1472,9 @@ sub print_review { $inst_values .= ''.$courseenv{'description'}.' '; my $cloneinst = $courseenv{'internal.coursecode'}; if ($cloneinst ne '') { - $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedom'}); + $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'}; } else { - $inst_values .= &mt('(from [_1])',$env{'form.clonedom'}); + $inst_values .= &mt('from').' '.$env{'form.clonedom'}; } $inst_values .= ''; if ($env{'form.datemode'} eq 'preserve') { @@ -1749,17 +1757,47 @@ sub coursecode_form { sub get_course_dom { my $codedom = &Apache::lonnet::default_login_domain(); + if ($env{'form.showdom'} ne '') { + if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') { + return $env{'form.showdom'}; + } + } if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) { + my ($types,$typename) = &course_types(); + if (ref($types) eq 'ARRAY') { + foreach my $type (@{$types}) { + if (&Apache::lonnet::usertools_access($env{'user.name'}, + $env{'user.domain'},$type, + undef,'requestcourses')) { + return $env{'user.domain'}; + } + } + my @possible_doms; + foreach my $type (@{$types}) { + my $dom_str = $env{'environment.reqcrsotherdom.'.$type}; + if ($dom_str ne '') { + my @domains = split(',',$dom_str); + foreach my $entry (@domains) { + my ($extdom,$extopt) = split(':',$entry); + if ($extdom eq $env{'request.role.domain'}) { + return $extdom; + } + unless(grep(/^\Q$extdom\E$/,@possible_doms)) { + push(@possible_doms,$extdom); + } + } + } + } + if (@possible_doms) { + @possible_doms = sort(@possible_doms); + return $possible_doms[0]; + } + } $codedom = $env{'user.domain'}; if ($env{'request.role.domain'} ne '') { $codedom = $env{'request.role.domain'}; } } - if ($env{'form.showdom'} ne '') { - if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') { - $codedom = $env{'form.showdom'}; - } - } return $codedom; } @@ -1808,6 +1846,7 @@ sub print_request_outcome { } $now = time; $crstype = $env{'form.crstype'}; + my @instsections; if ($crstype eq 'official') { if (&Apache::lonnet::auto_run('',$dom)) { ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend'); @@ -1815,7 +1854,11 @@ sub print_request_outcome { for (my $i=0; $i<$env{'form.sectotal'}; $i++) { if ($env{'form.sec_'.$i}) { if ($env{'form.secnum_'.$i} ne '') { - $sections{$i}{'inst'} = $env{'form.secnum_'.$i}; + my $sec = $env{'form.secnum_'.$i}; + $sections{$i}{'inst'} = $sec; + if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) { + push(@instsections,$sec); + } $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i}; } } @@ -1957,9 +2000,9 @@ sub print_request_outcome { my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig); if ($val eq '') { if ($crstype eq 'official') { - $output = &mt('You are not permitted to request creation of official courses'); + $output = &mt('You are not permitted to request creation of official courses.'); } elsif ($crstype eq 'unofficial') { - $output = &mt('You are not permitted to request creation of unofficial courses'); + $output = &mt('You are not permitted to request creation of unofficial courses.'); } elsif ($crstype eq 'community') { $output = &mt('You are not permitted to request creation of communities'); } else { @@ -1973,6 +2016,7 @@ sub print_request_outcome { details => $details, ); my $requestkey = $dom.'_'.$cnum; + my $validationerror; if ($val eq 'autolimit=') { $disposition = 'process'; } elsif ($val =~ /^autolimit=(\d+)$/) { @@ -1980,9 +2024,32 @@ sub print_request_outcome { $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'}, $dom,$crstype,$limit,\$message); } elsif ($val eq 'validate') { - $disposition = - &Apache::lonnet::auto_courserequest_validation($dom,$details, - \@inststatuses,\$message); + my $inststatuslist; + if (@inststatuses > 0) { + $inststatuslist = join(',',@inststatuses); + } + my $instseclist; + if (@instsections > 0) { + $instseclist = join(',',@instsections); + } + my $validation = + &Apache::lonnet::auto_validate_instcode('',$dom,$instcode, + $env{'user.name'}.':'.$env{'user.domain'},$inststatuslist, + $instseclist); + if ($validation eq 'valid') { + $disposition = 'process'; + } elsif ($validation eq 'rejected') { + $disposition = 'rejected'; + } elsif ($validation eq 'pending') { + $disposition = 'pending'; + } elsif ($disposition eq 'approval') { + $disposition = 'approval'; + } elsif ($disposition =~ /^error(.*)$/) { + $disposition = 'approval'; + $validationerror = $1; + } else { + $disposition = 'approval'; + } } else { $disposition = 'approval'; } @@ -2035,13 +2102,13 @@ sub print_request_outcome { my $statuskey = 'status:'.$dom.':'.$cnum; my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey], $env{'user.domain'},$env{'user.name'}); - if (exists($userreqhash{$statuskey})) { + if ($userreqhash{$statuskey} ne '') { $modified = 1; my %queuehash = &Apache::lonnet::get_dom('courserequestqueue', [$cnum.'_approval', $cnum.'_pending'],$dom); - if ((exists($queuehash{$cnum.'_approval'})) || - (exists($queuehash{$cnum.'_pending'}))) { + if (($queuehash{$cnum.'_approval'} ne '') || + ($queuehash{$cnum.'_pending'} ne '')) { $queued = 1; } } @@ -2084,6 +2151,9 @@ sub print_request_outcome { $output .= '

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

'. ¬ification_information($disposition,$req_notifylist,$cnum,$now); } + if ($validationerror ne '') { + $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'

'; + } } return $output; } @@ -2111,12 +2181,16 @@ sub notification_information { my $sender = $env{'user.name'}.':'.$env{'user.domain'}; &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender); } - } else { + } elsif ($disposition eq 'pending') { $output .= '
'. &mt('Your request has been placed in a queue pending administrative action.').'
'. &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'
'. &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.'). '
'; + } else { + $output .= '
'. + &mt('Your request status is: [_1].',$disposition). + '
' } return $output; } @@ -2125,7 +2199,7 @@ sub get_processtype { my ($dom,$crstype,$inststatuses,$domconfig) = @_; return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH')); my (%userenv,%settings,$val); - my @options = ('autolimit','validate','approve'); + my @options = ('autolimit','validate','approval'); if ($dom eq $env{'user.domain'}) { %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, @@ -2191,11 +2265,17 @@ sub get_processtype { } else { %userenv = &Apache::lonnet::userenvironment($env{'user.domain'}, $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'}); - if ($userenv{'reqcrsotherdom'}) { - my @doms = split(',',$userenv{'reqcrsotherdom'}); - my $optregex = join('|',@options); - if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) { - $val = $1; + if ($userenv{'reqcrsotherdom.'.$crstype}) { + my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype}); + my $optregex = join('|',@options); + foreach my $item (@doms) { + my ($extdom,$extopt) = split(':',$item); + if ($extdom eq $dom) { + if ($extopt =~ /^($optregex)(=?\d*)$/) { + $val = $1.$2; + } + last; + } } @{$inststatuses} = ('_external_'); } @@ -2317,7 +2397,7 @@ sub retrieve_settings { if (grep(/^\Q$sec\E/,@currsec)) { $env{'form.person_'.$i.'_sec'} = $sec; } else { - push (@newsecs,$sec); + push(@newsecs,$sec); } } } 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.