--- loncom/interface/lonrequestcourse.pm 2009/08/05 12:46:44 1.3 +++ loncom/interface/lonrequestcourse.pm 2009/08/12 02:04:38 1.9 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.3 2009/08/05 12:46:44 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.9 2009/08/12 02:04:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -55,7 +55,8 @@ use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; -use LONCAPA; +use Apache::loncoursequeueadmin; +use LONCAPA qw(:DEFAULT :match); sub handler { my ($r) = @_; @@ -113,9 +114,9 @@ sub handler { } my %trail = ( - crstype => 'Pick Action', - codepick => 'Pick Category', - courseinfo => 'Information', + crstype => 'Course Request Action', + codepick => 'Category', + courseinfo => 'Description', enrollment => 'Enrollment', personnel => 'Personnel', review => 'Review', @@ -190,8 +191,9 @@ sub handler { sub header { my ($bodytitle,$jscript,$loaditems,$jsextra) = @_; if ($jscript) { - $jscript = ''."\n"; + $jscript = ''."\n"; } if ($loaditems) { $loaditems = {'add_entries' => $loaditems,}; @@ -340,8 +342,9 @@ sub onload_action { sub check_can_request { my ($dom,$can_request) = @_; my $canreq = 0; - if (ref($can_request) eq 'HASH') { - foreach my $type ('official','unofficial','community') { + my ($types,$typename) = &course_types(); + if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) { + foreach my $type (@{$types}) { if (&Apache::lonnet::usertools_access($env{'user.name'}, $env{'user.domain'}, $type,undef,'requestcourses')) { @@ -366,8 +369,20 @@ sub check_can_request { return $canreq; } +sub course_types { + my @types = ('official','unofficial','community'); + my %typename = ( + official => 'Official course', + unofficial => 'Unofficial course', + community => 'Community', + ); + return (\@types,\%typename); +} + + sub print_main_menu { my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_; + my ($types,$typename) = &course_types(); my $onchange; unless ($env{'form.interface'} eq 'textual') { $onchange = 1; @@ -455,7 +470,7 @@ END '
'. '
'. &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title('Domain'). + &Apache::lonhtmlcommon::row_title('Course Domain'). &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange)); if (!$onchange) { $r->print('  - - - - - + '); + if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { + foreach my $type (@{$types}) { + my $selected = ''; + if ($type eq 'official') { + $selected = ' selected="selected"'; + } + $r->print(''."\n"); + } + } + $r->print(' '. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().'
@@ -515,13 +537,7 @@ END $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom); } $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb); - if ($state eq 'review') { - &print_review($r,$state,$dom); - } elsif ($state eq 'process') { - &print_request_outcome($r,$state,$dom); - } else { - &print_request_form($r,$action,$state,$page,$states,$dom); - } + &print_request_form($r,$action,$state,$page,$states,$dom); } elsif ($action eq 'view') { $r->print(&header('Manage course requests',$js.$jscript,$loaditems).$crumb); } elsif ($action eq 'log') { @@ -537,17 +553,23 @@ sub print_request_form { my ($next,$prev,$message,$output,$codepicker,$crstype); $prev = $states->{$action}[$page-1]; $next = $states->{$action}[$page+1]; + my %navtxt = &Apache::lonlocal::texthash ( + prev => 'Previous', + next => 'Next', + ); $crstype = $env{'form.crstype'}; $r->print(''); my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk); if ($crstype eq 'official') { - &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, - \%cat_order,\@code_order); if ($env{'form.instcode'} ne '') { $instcode = $env{'form.instcode'}; } } if ($prev eq 'codepick') { + if ($crstype eq 'official') { + &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, + \%cat_order,\@code_order); + } if (@code_order > 0) { my $message; if ($instcode eq '') { @@ -581,6 +603,10 @@ sub print_request_form { } } if ($prev eq 'crstype') { + if ($crstype eq 'official') { + &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, + \%cat_order,\@code_order); + } if (@code_order > 0) { $codepicker = &coursecode_form($dom,'instcode',\@codetitles, \%cat_titles,\%cat_order); @@ -596,10 +622,22 @@ sub print_request_form { } elsif ($prev eq 'codepick') { $r->print(&courseinfo_form($dom,$formname,$crstype)); } elsif ($state eq 'enrollment') { + if ($crstype eq 'official') { + &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, + \%cat_order,\@code_order); + } $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles, \%cat_titles,\%cat_order,\@code_order)); } elsif ($state eq 'personnel') { - $r->print(&print_personnel_menu($dom,$formname)); + $r->print(&print_personnel_menu($dom,$formname,$crstype)); + } elsif ($state eq 'review') { + &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, + \%cat_order,\@code_order); + $r->print(&print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order, + \@code_order)); + $navtxt{'next'} = &mt('Submit course request'); + } elsif ($state eq '') { + my $result = &print_request_outcome($dom); } my @excluded = ('counter'); my %elements = &form_elements($dom); @@ -625,7 +663,7 @@ sub print_request_form { push(@excluded,'instcode'); } $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); - &display_navbuttons($r,$formname,$prev,'Previous',$next,'Next'); + &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'}); return; } @@ -758,7 +796,7 @@ sub date_setting_table { } sub print_personnel_menu { - my ($dom,$formname) = @_; + my ($dom,$formname,$crstype) = @_; my $output = '
'.&Apache::lonhtmlcommon::start_pick_box(); my $persontotal = $env{'form.persontotal'}; if (!defined($persontotal)) { @@ -772,8 +810,12 @@ sub print_personnel_menu { my $roleoptions; my @roles = &Apache::lonuserutils::roles_by_context('course'); + my $type = 'Course'; + if ($crstype eq 'community') { + $type = 'Community'; + } foreach my $role (@roles) { - my $plrole=&Apache::lonnet::plaintext($role); + my $plrole=&Apache::lonnet::plaintext($role,$type); $roleoptions .= ' '."\n"; } my %customroles=&Apache::lonuserutils::my_custom_roles(); @@ -819,13 +861,13 @@ sub print_personnel_menu { for (my $i=0; $i<$persontotal; $i++) { my @linkargs = map { 'person_'.$i.'_'.$_ } (@items); my $linkargstr = join("','",@linkargs); - my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$userlinktxt); + my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt); my $uname_form = ''; + 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />'; my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',". "'person_".$i."_hidedom'".');'. - 'openuserbrowser('."'$formname','$linkargstr'".');'; + 'openuserbrowser('."'$formname','$linkargstr','$dom'".');'; my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','', 1,$onchange). ''; @@ -877,8 +919,225 @@ sub print_request_logs { } sub print_review { - my ($r,$state,$dom) = @_; - return; + my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_; + my ($types,$typename) = &course_types(); + my ($owner,$ownername,$owneremail); + $owner = $env{'user.name'}.':'.$env{'user.domain'}; + $ownername = &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'},'first'); + my %emails = &Apache::loncommon::getemails(); + foreach my $email ('permanentemail','critnotification','notification') { + $owneremail = $emails{$email}; + last if ($owneremail ne ''); + } + my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values, + $section_headers,$section_values,$personnel_headers,$personnel_values); + + $crstypename = $env{'form.crstype'}; + if (ref($typename) eq 'HASH') { + unless ($typename->{$env{'form.crstype'}} eq '') { + $crstypename = $typename->{$env{'form.crstype'}}; + } + } + + $inst_headers = ''.&mt('Description').''.&mt('Type').''; + $inst_values = ''.$env{'form.cdescr'}.''.$crstypename.''; + + if ($env{'form.crstype'} eq 'official') { + if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) { + foreach my $title (@{$codetitles}) { + if ($env{'form.instcode_'.$title} ne '') { + $inst_headers .= ''.$title.''; + my $longitem = $env{'form.instcode_'.$title}; + if (ref($cat_titles->{$title}) eq 'HASH') { + if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') { + $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}}; + } + } + $inst_values .= ''.$longitem.''; + } + } + } + if (&Apache::lonnet::auto_run('',$dom)) { + $enroll_headers = ''.&mt('Automatic Adds').''. + ''.&mt('Automatic Drops').''. + ''.&mt('Enrollment Starts').''. + ''.&mt('Enrollment Ends').''; + $section_headers = ''.&mt('Sections').''. + ''.&mt('Crosslistings').''; + + my ($startenroll,$endenroll) = &dates_from_form('startenroll','endenroll'); + my @autoroster = (&mt('No'),&mt('Yes')); + $enroll_values = ''.$autoroster[$env{'form.autoadds'}].''. + ''.$autoroster[$env{'form.autodrops'}].''. + ''.&Apache::lonlocal::locallocaltime($startenroll).''. + ''.&Apache::lonlocal::locallocaltime($endenroll).''; + $section_values = ''. + ''; + my $secinfo; + if ($env{'form.sectotal'} > 0) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + if ($env{'form.sec_'.$i}) { + $secinfo .= ''; + } + } + } + if ($secinfo eq '') { + $secinfo = ''; + } + $section_values .= $secinfo.'
'. + &mt('Institutional section').''.&mt('LON-CAPA section').'
'.$env{'form.secnum_'.$i}.''; + if ($env{'form.loncapasec_'.$i} ne '') { + $secinfo .= $env{'form.loncapasec_'.$i}; + } else { + $secinfo .= &mt('None'); + } + $secinfo .= '
'.&mt('None').'
'. + ''. + ''; + my $xlistinfo; + if ($env{'form.crosslisttotal'}) { + for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) { + if ($env{'form.crosslist_'.$i}) { + $xlistinfo .= ''; + } + } + } + if ($xlistinfo eq '') { + $xlistinfo = ''; + } + $section_values .= $xlistinfo.'
'. + &mt('Institutional course/section').''.&mt('LON-CAPA section').'
'; + if (ref($code_order) eq 'ARRAY') { + if (@{$code_order} > 0) { + foreach my $item (@{$code_order}) { + $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item}; + } + } + } + $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.''; + if ($env{'form.crosslist_'.$i.'_lcsec'}) { + $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'}; + } else { + $xlistinfo .= &mt('None'); + } + $xlistinfo .= '
'.&mt('None').'
'; + } + } + + my %ctxt = &clone_text(); + $inst_headers .= ''.&mt('Clone From').''; + if (($env{'form.clonecourse'} =~ /^$match_name$/) && + ($env{'form.clonedomain'} =~ /^$match_domain$/)) { + my %coursehash = + &Apache::lonnet::courseiddump($env{'form.clonedomain'},'.',1,'.','.', + $env{'form.clonecourse'},undef,undef,'.'); + my $cloneid = $env{'form.clonedomain'}.'_'.$env{'form.clonecourse'}; + if (ref($coursehash{$cloneid}) eq 'HASH') { + $inst_headers .= ''.$ctxt{'dsh'}.''; + my $clonedesc = $coursehash{$cloneid}{'description'}; + my $cloneinst = $coursehash{$cloneid}{'inst_code'}; + + $inst_values .= ''.$clonedesc.' '; + if ($cloneinst ne '') { + $inst_values .= &mt('([_1] in [_2])',$cloneinst,$env{'form.clonedomain'}); + } else { + $inst_values .= &mt('(from [_1])',$env{'form.clonedomain'}); + } + $inst_values .= ''; + if ($env{'form.datemode'} eq 'preserve') { + $inst_values .= $ctxt{'pcd'}; + } elsif ($env{'form.datemode'} eq 'shift') { + $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'}); + } else { + $inst_values .= $ctxt{'ncd'}; + } + $inst_values .= ''; + } else { + $inst_values .= ''.&mt('Unknown').''; + } + } else { + $inst_values .= ''.&mt('None').''; + } + $enroll_headers .= ''.&mt('Access Starts').''. + ''.&mt('Access Ends').''; + my ($startaccess,$endaccess) = &dates_from_form('startaccess','endaccess'); + $enroll_values .= ''.&Apache::lonlocal::locallocaltime($startaccess).''; + if ($endaccess == 0) { + $enroll_values .= ''.&mt('No end date').''; + } else { + $enroll_values .= ''.&Apache::lonlocal::locallocaltime($endaccess).''; + } + + my $container = 'Course'; + if ($env{'form.crstype'} eq 'community') { + $container = 'Community'; + } + + $personnel_headers = ''.&mt('Name').''.&mt('Username:Domain'). + ''.&mt('Role').''.&mt('LON-CAPA Sections'). + ''; + $personnel_values .= ''.$ownername.''.$owner.''. + ''.&Apache::lonnet::plaintext('cc',$container).''. + ''.&mt('None').''; + for (my $i=0; $i<$env{'form.persontotal'}; $i++) { + if ($env{'form.person_'.$i.'_uname'} ne '') { + $personnel_values .= + ''.$env{'form.person_'.$i.'_first'}.' '. + $env{'form.person_'.$i.'_last'}.''. + ''.$env{'form.person_'.$i.'_uname'}.':'. + $env{'form.person_'.$i.'_dom'}.''. + ''.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'}, + $container).''. + ''.$env{'form.person_'.$i.'_sections'}.''; + } + } + my $output = '

'.&mt('Review the details of the course request before submission.').'

'. + '
'.&Apache::lonhtmlcommon::start_pick_box(). + &Apache::lonhtmlcommon::row_title(&mt('Owner')). + ''. + ''. + ''. + ''. + ''."\n". + ''. + ''. + '
'.&mt('Name').''.&mt('Username:Domain').''.&mt('E-mail address').'
'.$ownername.''.$owner.''.$owneremail.'
'."\n". + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Description')). + ''.$inst_headers.''."\n". + ''.$inst_values.'
'."\n". + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title(&mt('Enrollment')). + ''.$enroll_headers.''."\n". + ''.$enroll_values.'
'."\n". + &Apache::lonhtmlcommon::row_closure(); + if ($section_headers ne '') { + $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')). + ''.$section_headers.''."\n". + ''.$section_values.'
'."\n". + &Apache::lonhtmlcommon::row_closure(); + } + $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')). + ''.$personnel_headers.''."\n". + $personnel_values.'
'."\n". + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box(); + my $cnum = &Apache::lonnet::generate_coursenum($dom); + $output .= ''; + return $output; +} + +sub dates_from_form { + my ($startname,$endname) = @_; + my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname); + my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname); + if ($endname eq 'endaccess') { + if (exists($env{'form.no_end_date'}) ) { + $enddate = 0; + } + } + return ($startdate,$enddate); } sub courseinfo_form { @@ -900,14 +1159,7 @@ sub clone_form { } my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedomain'). &Apache::loncommon::selectcourse_link($formname,'clonecourse','clonedomain','','','',$type); - my %lt = &Apache::lonlocal::texthash( - 'cid' => 'Course ID', - 'dmn' => 'Domain', - 'dsh' => 'Date Shift', - 'ncd' => 'Do not clone date parameters', - 'prd' => 'Clone date parameters as-is', - 'shd' => 'Shift date parameters by number of days', - ); + my %lt = &clone_text(); my $output .= &Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_title($lt{'cid'}).'