--- loncom/interface/lonrequestcourse.pm 2009/08/05 12:46:44 1.3 +++ loncom/interface/lonrequestcourse.pm 2009/08/12 14:39:23 1.12 @@ -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.12 2009/08/12 14:39:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,6 +44,62 @@ described at http://www.lon-capa.org. =item handler() +=item header() + +=item form_elements() + +=item onload_action() + +=item check_can_request() + +=item course_types() + +=item print_main_menu() + +=item request_administration() + +=item print_request_form() + +=item print_enrollment_menu() + +=item inst_section_selector() + +=item date_setting_table() + +=item print_personnel_menu() + +=item print_request_status() + +=item print_request_logs() + +=item print_review() + +=item dates_from_form() + +=item courseinfo_form() + +=item clone_form() + +=item clone_text() + +=item coursecode_form() + +=item get_course_dom() + +=item display_navbuttons() + +=item print_request_outcome() + +=item get_processtype() + +=item check_autolimit() + +=item build_batchcreatehash() + +=item retrieve_settings() + +=item get_request_settings() + =back =cut @@ -55,7 +111,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,13 +170,14 @@ sub handler { } my %trail = ( - crstype => 'Pick Action', - codepick => 'Pick Category', - courseinfo => 'Information', - enrollment => 'Enrollment', - personnel => 'Personnel', - review => 'Review', - process => 'Result', + crstype => 'Course Request Action', + codepick => 'Category', + courseinfo => 'Description', + enrollment => 'Enrollment', + personnel => 'Personnel', + review => 'Review', + process => 'Result', + pick_request => 'Display Summary', ); my $page = 0; @@ -178,7 +236,12 @@ sub handler { ''.&Apache::loncommon::end_page()); } } elsif ($action eq 'view') { - &print_request_status($jscript,$loaditems,$crumb); + if ($state eq 'crstype') { + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb); + } else { + &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, + $loaditems,$crumb); + } } elsif ($action eq 'log') { &print_request_logs($jscript,$loaditems,$crumb); } else { @@ -190,8 +253,9 @@ sub handler { sub header { my ($bodytitle,$jscript,$loaditems,$jsextra) = @_; if ($jscript) { - $jscript = ''."\n"; + $jscript = ''."\n"; } if ($loaditems) { $loaditems = {'add_entries' => $loaditems,}; @@ -340,8 +404,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 +431,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 +532,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,17 +599,14 @@ 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); + if ($state eq 'pick_request') { + $r->print(&print_request_status($dom)); + } } elsif ($action eq 'log') { - $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb); + $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb); } $r->print(&Apache::loncommon::end_page()); return; @@ -537,17 +618,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 => 'Back', + 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 +668,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 +687,26 @@ 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 'process') { + if ($crstype eq 'official') { + &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, + \%cat_order,\@code_order); + } + my $result = &print_request_outcome($dom,\@codetitles,\@code_order); } my @excluded = ('counter'); my %elements = &form_elements($dom); @@ -625,7 +732,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 +865,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 +879,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 +930,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). ''; @@ -869,16 +980,314 @@ sub print_personnel_menu { } sub print_request_status { - return; + my ($dom) = @_; + my %requests = &Apache::lonnet::dumpstore('courserequests',$env{'user.domain'}, + $env{'user.name'}); + my ($output,$formname,%queue_by_date); + foreach my $key (keys(%requests)) { + if (ref($requests{$key}) eq 'HASH') { + my ($cdom,$cnum) = split('_',$key); + next if ($cdom ne $dom); + my $entry; + my $timestamp = $requests{$key}{'timestamp'}; + my $crstype = $requests{$key}{'crstype'}; + my $status = $requests{$key}{'status'}; + next unless (($env{'form.crstype'} eq 'all') || + ($env{'form.crstype'} eq $crstype)); + next unless (($status eq 'approval') || ($status eq 'pending')); + if (ref($requests{$key}{'details'}) eq 'HASH') { + $entry = $key.':'.$crstype.':'.$requests{$key}{'details'}{'cdesc'}; + if ($crstype eq 'official') { + $entry .= ':'.$requests{$key}{'details'}{'instcode'}; + } + } + if ($entry ne '') { + if (exists($queue_by_date{$timestamp})) { + if (ref($queue_by_date{$timestamp}) eq 'ARRAY') { + push(@{$queue_by_date{$timestamp}},$entry); + } + } else { + @{$queue_by_date{$timestamp}} = ($entry); + } + } + } + } + $formname = 'requestcrs'; + my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); + $output = '
'."\n". + ''."\n". + ''."\n". + ''."\n"; + if (@sortedtimes > 0) { + $output .= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('Action').''. + ''.&mt('Description').''; + if ($env{'form.crstype'} eq 'all') { + $output .= ''.&mt('Type').''; + } + if (($env{'form.crstype'} eq 'all') || ($env{'form.crstype'} eq 'official')) { + $output .= ''.&mt('Institutional Code').''; + } + $output .= ''.&mt('Date requested').''. + &Apache::loncommon::end_data_table_header_row(); + my $count = 0; + foreach my $item (@sortedtimes) { + my $showtime = &Apache::lonlocal::locallocaltime($item); + if (ref($queue_by_date{$item}) eq 'ARRAY') { + foreach my $request (sort(@{$queue_by_date{$item}})) { + my ($key,$type,$desc,$instcode) = split(':',$request); + my ($cdom,$cnum) = split('_',$key); + $output .= &Apache::loncommon::start_data_table_row(). + ''. + ''.$desc.''; + if ($env{'form.crstype'} eq 'all') { + $output .= ''.&course_types($type).''; + } + if (($env{'form.crstype'} eq 'all') || + ($env{'form.crstype'} eq 'official')) { + $output .= ''.$instcode.''; + } + $output .= ''.$showtime.''. + &Apache::loncommon::end_data_table_row(); + } + } + } + $output .= &Apache::loncommon::end_data_table(); + } else { + $output .= '
'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'; + } + $output .= ' + +
'; + return $output; } sub print_request_logs { + my ($jscript,$loaditems,$crumb) = @_; return; } 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 +1309,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'}).'