--- loncom/interface/loncoursequeueadmin.pm 2010/03/30 16:02:27 1.24 +++ loncom/interface/loncoursequeueadmin.pm 2011/11/30 12:31:00 1.29 @@ -1,7 +1,7 @@ # The LearningOnline Network # Utilities to administer domain course requests and course self-enroll requests # -# $Id: loncoursequeueadmin.pm,v 1.24 2010/03/30 16:02:27 raeburn Exp $ +# $Id: loncoursequeueadmin.pm,v 1.29 2011/11/30 12:31:00 goltermann Exp $ # # Copyright Michigan State University Board of Trustees # @@ -90,8 +90,8 @@ sub send_selfserve_notification { # FIXME locallocaltime needs to be able to take $sender_lh as an argument # so this can be localized to the recipients date display format/time zone $timestamp =&Apache::lonlocal::locallocaltime($timestamp); - my $msgcc; - my ($rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt); + my ($msgcc,$rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt); + my ($senderuname,$senderudom) = split(':',$sender); if ($context eq 'coursemanagers') { $rawsubj = 'Self-enrollment requests processed'; push(@rawmsg,{ @@ -138,6 +138,15 @@ sub send_selfserve_notification { if (ref($textstr) eq 'ARRAY') { push(@rawmsg,@{$textstr}); } + } elsif ($context eq 'pendingrequestor') { + if ($crstype eq 'Community') { + $rawsubj = 'Community request'; + } else { + $rawsubj = 'Processed course request'; + } + if (ref($textstr) eq 'ARRAY') { + push(@rawmsg,@{$textstr}); + } } elsif ($context eq 'coursereq') { if ($crstype eq 'community') { $rawsubj = 'Community request to review'; @@ -213,7 +222,7 @@ sub send_selfserve_notification { $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n"; } } - &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms); + &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms,undef,undef,undef,undef,$senderuname,$senderudom); my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash); my $status; foreach my $recip (sort(keys(%{$msgcc}))) { @@ -415,9 +424,11 @@ sub build_queue_display { } unless ($context eq 'pending') { $row = '
'. + ''.&mt('Approve').''. '
'; + ''.&mt('Reject').''. + ''.&mt('Decide Later'). + '
'; } $row .= ''.$namelink.''."\n"; if ($context eq 'course') { @@ -446,14 +457,25 @@ sub build_queue_display { sub update_request_queue { my ($context,$cdom,$cnum,$coursedesc) = @_; my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace, - $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol, - $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary, + $stucounts,$idx,$classlist,%requesthash,$cid,$domdesc,$now, + $sender,$approvedmsg,$rejectedmsg,$beneficiary, @existing,@missingreq,@invalidusers,@limitexceeded,@completed, @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels, @rejections,@rejectionerrors,@nopermissions,%courseroles, - %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue); - @approvals = &Apache::loncommon::get_env_multiple('form.approvereq'); - @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq'); + %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue,$firsturl); + my $count=0; + while (my @course = &Apache::loncommon::get_env_multiple('form.'.$count.'radioreq')) { + if (@course[0] =~ /^\d+:.*/) { + push(@approvals,@course[0]); + } elsif (@course[0] =~ /^later:.*/) { + #decide later + } else { + push(@rejections,@course[0]); + } + $count+=1; + } + + $now = time; $sender = $env{'user.name'}.':'.$env{'user.domain'}; if ($context eq 'course') { @@ -461,10 +483,7 @@ sub update_request_queue { $beneficiary = 'enroller'; $cid = $env{'request.course.id'}; $crstype = lc(&Apache::loncommon::course_type()); - my $chome = &Apache::lonnet::homeserver($cnum,$cdom); - $hostname = &Apache::lonnet::hostname($chome); - $protocol = $Apache::lonnet::protocol{$chome}; - $protocol = 'http' if ($protocol ne 'https'); + $firsturl = &course_portal_url($cnum,$cdom); %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum); $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'}; $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'}; @@ -476,8 +495,8 @@ sub update_request_queue { mt => 'Your request for enrollment has been approved.', }, { - mt => 'Visit [_1], to log-in and access the course', - args => [$protocol.'://'.$hostname], + mt => 'Visit [_1] to log-in and access the course', + args => [$firsturl], }]; $rejectedmsg = [{ mt => 'Your request for enrollment has not been approved.', @@ -491,10 +510,6 @@ sub update_request_queue { $queue = 'pending'; } %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_'.$queue); - my $chome = &Apache::lonnet::domain($cdom,'primary'); - $hostname = &Apache::lonnet::hostname($chome); - $protocol = $Apache::lonnet::protocol{$chome}; - $protocol = 'http' if ($protocol ne 'https'); my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom); if (ref($domconfig{'requestcourses'}) eq 'HASH') { if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') { @@ -506,8 +521,8 @@ sub update_request_queue { mt => 'Your course request has been approved.', }, { - mt => 'Visit [_1], to log-in and access the course', - args => [$protocol.'://'.$hostname], + mt => 'Visit [_1] to log-in and access the course', + args => [], }]; $rejectionmsg{'course'} = [{ @@ -519,8 +534,8 @@ sub update_request_queue { mt => 'Your community request has been approved.', }, { - mt => 'Visit [_1], to log-in and access the community', - args => [$protocol.'://'.$hostname], + mt => 'Visit [_1] to log-in and access the community', + args => [], }]; $rejectionmsg{'community'} = @@ -576,7 +591,8 @@ sub update_request_queue { $stucounts->{'allstudents'} ++; $stucounts->{'selfenrolled'} ++; &send_selfserve_notification($uname.':'.$udom,$approvedmsg, - $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype); + $cid,$coursedesc,$now,$beneficiary,$sender, + undef,undef,$crstype); my %userrequest = ( $cdom.'_'.$cnum => { timestamp => $now, @@ -641,13 +657,20 @@ sub update_request_queue { } else { $approvedmsg = $approvalmsg{'course'}; } + my $firsturl = &course_portal_url($cnum,$cdom); + if (ref($approvedmsg) eq 'ARRAY') { + if (ref($approvedmsg->[1]) eq 'HASH') { + $approvedmsg->[1]->{'args'} = [$firsturl]; + } + } push(@completed,$cnum); unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') { push(@warn_dels,$cnum); } - &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg, - $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype); + &send_selfserve_notification($ownername.':'.$ownerdom, + $approvedmsg,$cid,$coursedesc,$now, + $beneficiary,$sender,undef,undef,$crstype); my %reqhash = ( reqtime => $history{'reqtime'}, crstype => $history{'crstype'}, @@ -700,7 +723,8 @@ sub update_request_queue { if ($context eq 'course') { my $user = $item; &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc, - $now,$beneficiary,$sender,undef,undef,$crstype); + $now,$beneficiary,$sender,undef,undef, + $crstype); my ($uname,$udom) = split(/:/,$user); my %userrequest = ( $cdom.'_'.$cnum => { @@ -996,6 +1020,22 @@ sub update_request_queue { return $output; } +sub course_portal_url { + my ($cnum,$cdom) = @_; + my $chome = &Apache::lonnet::homeserver($cnum,$cdom); + my $hostname = &Apache::lonnet::hostname($chome); + my $protocol = $Apache::lonnet::protocol{$chome}; + $protocol = 'http' if ($protocol ne 'https'); + my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); + my $firsturl; + if ($domdefaults{'portal_def'}) { + $firsturl = $domdefaults{'portal_def'}; + } else { + $firsturl = $protocol.'://'.$hostname; + } + return $firsturl; +} + sub get_student_counts { my ($cdom,$cnum) = @_; my (%idx,%stucounts); @@ -1283,17 +1323,17 @@ sub queued_selfenrollment { } sub update_coursereq_status { - my ($reqhash,$dom,$cnum,$reqstatus,$context) = @_; + my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_; my ($storeresult,$statusresult,$output); my $requestkey = $dom.'_'.$cnum; if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey, - 'courserequests'); + 'courserequests',$udom,$uname); if ($storeresult eq 'ok') { my %status = ( 'status:'.$dom.':'.$cnum => $reqstatus, ); - $statusresult = &Apache::lonnet::put('courserequests',\%status); + $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname); } } else { $storeresult = 'error: invalid requestkey format'; @@ -1305,7 +1345,7 @@ sub update_coursereq_status { } else { $output = ''.$output.'
'; } - &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult"); + &Apache::lonnet::logthis("Error saving course request - $requestkey for $uname:$udom - $storeresult"); } elsif ($statusresult ne 'ok') { $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult); if ($context eq 'domain') { @@ -1313,13 +1353,13 @@ sub update_coursereq_status { } else { $output = ''.$output.'
'; } - &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult"); + &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $uname:$udom) - $statusresult"); } return ($storeresult,$output); } sub process_official_reqs { - my ($context,$dom) = @_; + my ($context,$dom,$dcname,$dcdom) = @_; my $reqsnamespace = 'courserequestqueue'; my %requesthash = &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending'); @@ -1397,7 +1437,31 @@ sub process_official_reqs { if ($result eq 'created') { $disposition = 'created'; $reqstatus = 'created'; - push(@{$newcids{$instcode}},$dom.'_'.$cnum); + my $cid = $dom.'_'.$cnum; + push(@{$newcids{$instcode}},$cid); + if ($dcname && $dcdom) { + my $firsturl = &course_portal_url($cnum,$dom); + my $beneficiary = 'pendingrequestor'; + my $now = time; + my $owner = $ownername.':'.$ownerdom; + my $approvedmsg = + [{ + mt => 'Your requested course: [_1], (queued pending validation) has now been created.', + args => [$cdescr], + }, + { + mt => 'Visit [_1] to log-in and access the course.', + args => [$firsturl], + }, + { + mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.' + }]; + my $sender = $dcname.':'.$dcdom; + &send_selfserve_notification($owner,$approvedmsg, + $cid,$cdescr,$now, + $beneficiary,$sender, + undef,undef,$crstype); + } } } elsif ($disposition eq 'rejected') { $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed; @@ -1433,7 +1497,8 @@ sub process_official_reqs { unless ($disposition eq 'pending') { my ($statusresult,$output) = &update_coursereq_status(\%requesthash,$dom,$cnum, - $reqstatus,'domain'); + $reqstatus,'domain',$ownerdom, + $ownername); unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') { $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed; }