--- loncom/interface/lonrequestcourse.pm 2009/08/15 01:59:04 1.13 +++ loncom/interface/lonrequestcourse.pm 2009/08/16 19:16:16 1.14 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.13 2009/08/15 01:59:04 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.14 2009/08/16 19:16:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -395,7 +395,6 @@ sub form_elements { $people{'person_'.$i.'_role'} = 'selectbox', $people{'person_'.$i.'_sec'} = 'selectbox', $people{'person_'.$i.'_newsec'} = 'text', - $people{'person_'.$i.'_sections'} = 'hidden', } my %personnelhash = (%{$elements{'new'}{'personnel'}},%people); %{$elements{'new'}{'personnel'}} = %personnelhash; @@ -553,7 +552,8 @@ END my $formname = 'requestcrs'; my $nexttext = &mt('Next'); - $r->print('
'. + $r->print( + '
'. &Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_title('Action').' @@ -855,13 +855,13 @@ sub inst_section_selector { } sub date_setting_table { - my ($starttime,$endtime,$formname,$suffix,%datetitles) = @_; + my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_; my ($perpetual,$table); - my $startform = &Apache::lonhtmlcommon::date_setter($formname,'start'.$suffix, + my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start', $starttime,'','','',1,'','','',1); - my $endform = &Apache::lonhtmlcommon::date_setter($formname,'end'.$suffix, + my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end', $endtime,'','','',1,'','','',1); - if ($suffix eq 'access') { + if ($prefix eq 'access') { $perpetual = ' '; @@ -965,9 +965,7 @@ sub print_personnel_menu { $existmult.'>'."\n".$existops.''.(' ' x3); } $sectionselector .= $newtitle. - ''. - ''."\n"; - + ''."\n"; $output .= &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'
'. ''.$userlink. @@ -992,40 +990,56 @@ sub print_personnel_menu { sub print_request_status { 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'}{'cdescr'}; - 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); + my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, + $env{'user.name'},'^status:'.$dom); + my ($output,$formname,%queue_by_date,%typenames); + if ($env{'form.crstype'} eq 'any') { + %typenames = &Apache::lonlocal::texthash ( + official => 'Official course', + unofficial => 'Unofficial course', + community => 'Community', + ); + } + foreach my $key (keys(%statusinfo)) { + if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { + (undef,my($cdom,$cnum)) = split(':',$key); + next if ($cdom ne $dom); + my $requestkey = $cdom.'_'.$cnum; + if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { + my %history = &Apache::lonnet::restore($requestkey,'courserequests', + $env{'user.domain'},$env{'user.name'}); + my $entry; + my $timestamp = $history{'reqtime'}; + my $crstype = $history{'crstype'}; + my $disposition = $history{'disposition'}; + next if ((exists($history{'status'})) && ($history{'status'} eq 'created')); + next unless (($env{'form.crstype'} eq 'any') || + ($env{'form.crstype'} eq $crstype)); + next unless (($disposition eq 'approval') || + ($disposition eq 'pending')); + if (ref($history{'details'}) eq 'HASH') { + $entry = $requestkey.':'.$crstype.':'. + &escape($history{'details'}{'cdescr'}); + if ($crstype eq 'official') { + $entry .= ':'.&escape($history{'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); } - } else { - @{$queue_by_date{$timestamp}} = ($entry); } } } } $formname = 'requestcrs'; my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); - $output = ''."\n". + $output = '

'.&mt('Pending course requests').'

'."\n". + ''."\n". ''."\n". ''."\n". ''."\n"; @@ -1033,11 +1047,12 @@ sub print_request_status { $output .= &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). ''.&mt('Action').''. - ''.&mt('Description').''; - if ($env{'form.crstype'} eq 'all') { + ''.&mt('Course Description').''. + ''.&mt('Domain').''; + if ($env{'form.crstype'} eq 'any') { $output .= ''.&mt('Type').''; } - if (($env{'form.crstype'} eq 'all') || ($env{'form.crstype'} eq 'official')) { + if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) { $output .= ''.&mt('Institutional Code').''; } $output .= ''.&mt('Date requested').''. @@ -1051,13 +1066,24 @@ sub print_request_status { my ($cdom,$cnum) = split('_',$key); $output .= &Apache::loncommon::start_data_table_row(). ''. - ''.$desc.''; - if ($env{'form.crstype'} eq 'all') { - $output .= ''.&course_types($type).''; + ''.&unescape($desc).''. + ''.$cdom.''; + if ($env{'form.crstype'} eq 'any') { + my $typename = $typenames{$type}; + if ($typename eq '') { + $typename = &mt('Unknown type'); + } + $output .= ''.$typename.''; } - if (($env{'form.crstype'} eq 'all') || + if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) { - $output .= ''.$instcode.''; + my $showinstcode; + if ($type eq 'official') { + $showinstcode = &unescape($instcode); + } else { + $showinstcode = &mt('Not applicable'); + } + $output .= ''.$showinstcode.''; } $output .= ''.$showtime.''. &Apache::loncommon::end_data_table_row(); @@ -1069,8 +1095,8 @@ sub print_request_status { $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; } @@ -1243,6 +1269,24 @@ sub print_review { ''.&mt('None').''; for (my $i=0; $i<$env{'form.persontotal'}; $i++) { if ($env{'form.person_'.$i.'_uname'} ne '') { + my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec'); + my $newsec = $env{'form.person_'.$i.'_newsec'}; + $newsec =~ s/^\s+//; + $newsec =~s/\s+$//; + my @newsecs = split(/[\s,;]+/,$newsec); + foreach my $sec (@newsecs) { + next if ($sec =~ /\W/); + next if ($newsec eq 'none'); + if ($sec ne '') { + unless (grep(/^\Q$sec\E$/,@allsecs)) { + push(@allsecs,$sec); + } + } + } + my $showsec = 'None'; + if (@allsecs) { + $showsec = join(', ',@allsecs); + } $personnel_values .= ''.$env{'form.person_'.$i.'_firstname'}.' '. $env{'form.person_'.$i.'_lastname'}.''. @@ -1250,7 +1294,7 @@ sub print_review { $env{'form.person_'.$i.'_dom'}.''. ''.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'}, $container).''. - ''.$env{'form.person_'.$i.'_sections'}.''; + ''.$showsec.''; } } my $output = '

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

'. @@ -1532,8 +1576,10 @@ sub print_request_outcome { $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'}; } } + } else { + $enrollstart = ''; + $enrollend = ''; } - for (my $i=0; $i<$env{'form.persontotal'}; $i++) { my $uname = $env{'form.person_'.$i.'_uname'}; my $udom = $env{'form.person_'.$i.'_uname'}; @@ -1559,15 +1605,17 @@ sub print_request_outcome { if ($role eq 'cc') { @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = (); } else { - my @currsec; - if ($env{'form.person_'.$i.'_sections'} ne '') { - my @sections = split(',',$env{'form.person_'.$i.'_sections'}); - foreach my $sec (@sections) { - next if ($sec eq ''); - if (@currsec > 0) { - unless(grep(/^\Q$sec\E$/,@currsec)) { - push(@currsec,$sec); - } + my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec'); + my $newsec = $env{'form.person_'.$i.'_newsec'}; + $newsec =~ s/^\s+//; + $newsec =~s/\s+$//; + my @newsecs = split(/[\s,;]+/,$newsec); + foreach my $sec (@newsecs) { + next if ($sec =~ /\W/); + next if ($newsec eq 'none'); + if ($sec ne '') { + unless (grep(/^\Q$sec\E$/,@currsec)) { + push(@currsec,$sec); } } } @@ -1582,6 +1630,29 @@ sub print_request_outcome { } } my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend'); + my $autodrops = 0; + if ($env{'form.autodrops'}) { + $autodrops = $env{'form.autodrops'}; + } + my $autoadds = 0; + if ($env{'form.autoadds'}) { + $autodrops = $env{'form.autoadds'}; + } + my $sectotal = 0; + if ($env{'form.sectotal'}) { + $sectotal = $env{'form.sectotal'}; + } + if ($env{'form.autoadds'}) { + $autodrops = $env{'form.autoadds'}; + } + my $crosslisttotal = 0; + if ($env{'form.crosslisttotal'}) { + $crosslisttotal = $env{'form.crosslisttotal'}; + } + my $instcode = ''; + if (exists($env{'form.instcode'})) { + $instcode = $env{'form.instcode'}; + } my $details = { owner => $env{'user.name'}, domain => $env{'user.domain'}, @@ -1590,17 +1661,17 @@ sub print_request_outcome { coursehome => $env{'form.chome'}, cdescr => $env{'form.cdescr'}, crstype => $env{'form.crstype'}, - instcode => $env{'form.instcode'}, + instcode => $instcode, clonedom => $env{'form.clonedom'}, clonecrs => $env{'form.clonecrs'}, datemode => $env{'form.datemode'}, - dateshift => $env{'form.datshift'}, - sectotal => $env{'form.sectotal'}, + dateshift => $env{'form.dateshift'}, + sectotal => $sectotal, sections => \%sections, - crosslisttotal => $env{'form.crosslisttotal'}, + crosslisttotal => $crosslisttotal, crosslists => \%crosslistings, - autoadds => $env{'form.autoadds'}, - autodrops => $env{'form.autodrops'}, + autoadds => $autoadds, + autodrops => $autodrops, enrollstart => $enrollstart, enrollend => $enrollend, accessstart => $accessstart, @@ -1620,9 +1691,9 @@ sub print_request_outcome { $output = &mt('Unrecognized course type: [_1]',$crstype); } } else { - my ($disposition,$message); + my ($disposition,$message,$reqstatus); my %reqhash = ( - timestamp => $now, + reqtime => $now, crstype => $crstype, details => $details, ); @@ -1640,37 +1711,39 @@ sub print_request_outcome { } else { $disposition = 'approval'; } - $reqhash{'status'} = $disposition; + $reqhash{'disposition'} = $disposition; + $reqstatus = $disposition; if ($disposition eq 'rejected') { $output = &mt('Your course request was rejected.'); if ($message) { $output .= '
'.$message.'
'; } } elsif ($disposition eq 'process') { + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles); + my @roles = &Apache::lonuserutils::roles_by_context('course'); my $type = 'Course'; if ($crstype eq 'community') { $type = 'Community'; } - my %domdefs = &Apache::lonnet::get_domain_defaults($dom); - my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles); - my @roles = &Apache::lonuserutils::roles_by_context('course'); foreach my $role (@roles) { $longroles{$role}=&Apache::lonnet::plaintext($role,$type); } - my $owneremail; - my %emails = &Apache::loncommon::getemails(); - foreach my $email ('permanentemail','critnotification','notification') { - $owneremail = $emails{$email}; - last if ($owneremail ne ''); - } - my %reqdetails = &build_batchcreatehash($dom,$details,$owneremail,\%domdefs); - my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',\%reqdetails,\%longroles,\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$output,\$keysmsg,$env{'user.domain'},$env{'user.name'},$cnum,$crstype); - $disposition = 'created'; - if ($cid eq "/$dom/$cnum") { + my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum, + 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult, + \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles); + if ($result eq 'created') { $disposition = 'created'; - $output = &mt('Your course request has been processed and the course has been created.').'
'.&mt('You will need to logout and log-in again to be able to select a role in the course.'); + $reqstatus = 'created'; + $output = &mt('Your course request has been processed and the course has been created.'). + '
'. + &mt('You will need to logout and log-in again to be able to select a role in the course.'); } else { - $output = &mt('An error occurred when processing your course request.').'
'.&mt('You may want to review the request details and submit the request again.'); + $output = ''. + &mt('An error occurred when processing your course request.'). + '
'. + &mt('You may want to review the request details and submit the request again.'). + '
'; } } else { my $requestid = $cnum.'_'.$disposition; @@ -1696,16 +1769,16 @@ sub print_request_outcome { } $output = &mt('Your course request has been recorded.').'
'; if ($disposition eq 'approval') { - $output .= &mt('Your course request has been recorded.').'
'. - &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'
'. - &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'
'; + $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'
'. + &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'
'; if ($address ne '') { $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'
'; } if ($req_notifylist) { my $fullname = &Apache::loncommon::plainname($env{'user.name'}, $env{'user.domain'}); - &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,$fullname,$now,$dom,$details); + 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 { $output .= '
'. @@ -1715,23 +1788,32 @@ sub print_request_outcome { '
'; } } else { - $reqhash{'status'} = 'domainerror'; + $reqstatus = 'domainerror'; $reqhash{'disposition'} = $disposition; my $warning = &mt('An error occurred saving your request in the pending requests queue.'); $output = ''.$warning.'
'; } } - my $storeresult; + my ($storeresult,$statusresult); if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey, 'courserequests'); + if ($storeresult eq 'ok') { + my %status = ( + 'status:'.$dom.':'.$cnum => $reqstatus, + ); + $statusresult = &Apache::lonnet::put('courserequests',\%status); + } } else { $storeresult = 'error: invalid requestkey format'; } if ($storeresult ne 'ok') { $output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'
'; &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult"); + } elsif ($statusresult ne 'ok') { + $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'
'; + &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult"); } } return $output; @@ -1853,38 +1935,6 @@ sub check_autolimit { return; } -sub build_batchcreatehash { - my ($dom,$details,$owneremail,$domdefs) = @_; - my %batchhash; - my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users}; - if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) { - my $emailenc = &Apache::lonnet::escape($owneremail); - my $owner = $details->{'owner'}.':'.$details->{'domain'}; - foreach my $item (@items) { - $batchhash{$item} = $details->{$item}; - } - $batchhash{'title'} = $details->{'cdescr'}; - $batchhash{'coursecode'} = $details->{'instcode'}; - $batchhash{'emailenc'} = $emailenc; - $batchhash{'adds'} = $details->{'autoadds'}; - $batchhash{'drops'} = $details->{'autodrops'}; - $batchhash{'authtype'} = $domdefs->{'auth_def'}; - $batchhash{'authparam'} = $domdefs->{'auth_arg_def'}; - if ($details->{'crstype'} eq 'community') { - $batchhash{'crstype'} = 'Community'; - } else { - $batchhash{'crstype'} = 'Course'; - } - $batchhash{'users'}{$details->{$owner}} = { - firstname => $env{'environment.first'}, - lastname => $env{'environment.last'}, - emailenc => $emailenc, - email => $owneremail, - }; - } - return %batchhash; -} - sub retrieve_settings { my ($dom,$request_id) = @_; my %reqinfo = &get_request_settings($request_id,$dom);