--- loncom/interface/lonrequestcourse.pm 2009/08/05 12:46:44 1.3
+++ loncom/interface/lonrequestcourse.pm 2009/08/05 23:44:52 1.4
@@ -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.4 2009/08/05 23:44:52 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,7 +55,7 @@ use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
my ($r) = @_;
@@ -113,8 +113,8 @@ sub handler {
}
my %trail = (
- crstype => 'Pick Action',
- codepick => 'Pick Category',
+ crstype => 'Course Request Action',
+ codepick => 'Category',
courseinfo => 'Information',
enrollment => 'Enrollment',
personnel => 'Personnel',
@@ -340,8 +340,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 +367,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;
@@ -478,11 +491,18 @@ END
&Apache::lonhtmlcommon::row_closure().
&Apache::lonhtmlcommon::row_title('Course Type').'
+ ');
+ 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,9 +535,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') {
+ if ($state eq 'process') {
&print_request_outcome($r,$state,$dom);
} else {
&print_request_form($r,$action,$state,$page,$states,$dom);
@@ -537,17 +555,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('
');
- &display_navbuttons($r,$formname,$prev,'Previous',$next,'Next');
+ &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'});
return;
}
@@ -877,8 +915,208 @@ 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 = '';
+ if ($env{'form.sectotal'} > 0) {
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ if ($env{'form.sec_'.$i}) {
+ $section_values .= $env{'form.secnum_'.$i};
+ if ($env{'form.loncapasec_'.$i} ne '') {
+ $section_values .= ' => '.$env{'form.loncapasec_'.$i};
+ }
+ $section_values .= ' ';
+ }
+ }
+ }
+ $section_values .= ' | ';
+ if ($env{'form.crosslisttotal'}) {
+ for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+ if ($env{'form.crosslist_'.$i}) {
+ if (ref($codetitles) eq 'ARRAY') {
+ if (@{$codetitles} > 0) {
+ foreach my $item (@{$codetitles}) {
+ $section_values .= $env{'form.crosslist_'.$i.'_'.$item};
+ }
+ } else {
+ $section_values .= $env{'form.crosslist_'.$i.'_instsec'};
+ }
+ } else {
+ $section_values .= $env{'form.crosslist_'.$i.'_instsec'};
+ }
+ if ($env{'form.crosslist_'.$i.'_lcsec'}) {
+ $section_values .= ' => '.$env{'form.crosslist_'.$i.'_lcsec'};
+ }
+ $section_values .= ' ';
+ }
+ }
+ }
+ $section_values .= ' | ';
+ }
+ }
+
+ 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')).
+ '
'.
+ ''.&mt('Name').' | '.
+ ''.&mt('Username:Domain').' | '.
+ ''.&mt('E-mail address').' | '.
+ ''."\n".
+ ''.$ownername.' | '.$owner.' | '.
+ ''.$owneremail.' | '.
+ '
'."\n".
+ &Apache::lonhtmlcommon::row_closure().
+ &Apache::lonhtmlcommon::row_title(&mt('Information')).
+ '
'.$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();
+ 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 +1138,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'}).'