--- loncom/interface/selfenroll.pm 2009/02/09 04:11:11 1.16 +++ loncom/interface/selfenroll.pm 2010/01/18 15:58:25 1.25.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Allow users to self-enroll in a course # -# $Id: selfenroll.pm,v 1.16 2009/02/09 04:11:11 raeburn Exp $ +# $Id: selfenroll.pm,v 1.25.2.1 2010/01/18 15:58:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,6 +34,7 @@ use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; use Apache::createaccount; +use Apache::loncoursequeueadmin; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -404,7 +405,7 @@ sub has_role { my $output; if ($curr_role{'status'} eq 'active') { my $rolelink = &jump_to_role($curr_role{'role'}); - $output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'
'.$rolelink; + $output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'
'.$rolelink; } elsif ($curr_role{'status'} eq 'future') { $output = &mt('You have a student role (section: "[_1]") in this course which will become active [_2].',$curr_role{'section'},$curr_role{'start'}); } @@ -475,7 +476,7 @@ sub process_self_enroll { } &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, $area); - &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups); + &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); $userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; &Apache::lonnet::appenv(\%userroles,[$role,'cm']); $r->print('

'.&mt('Enrollment process complete').'

'); @@ -542,8 +543,8 @@ sub store_selfenroll_request { my %existing = &Apache::lonnet::get($namespace,[$uname.':'.$udom],$cdom,$cnum); if ($existing{$uname.':'.$udom}) { - my ($timestamp,$sec) = split(/:/,$existing{$uname.':'.$udom}); - $output = &mt('A self-enrollment request already exists for you for this course.').'
'.&mt('Your earlier request was submitted: [_1] and remains in a queue awaiting action by a Course Coordinator.',&Apache::lonlocal::locallocaltime($timestamp)); + $output = &mt('A self-enrollment request already exists for you for this course.').'
'.&mt('Your earlier request is in a queue awaiting action by a Course Coordinator.'). + '

'.&Apache::loncoursequeueadmin::queued_selfenrollment(); } else { my %selfenroll = ( $uname.':'.$udom => $now.':'.$usec, @@ -562,7 +563,8 @@ sub store_selfenroll_request { $warning = &mt('An error occurred saving a personal record of your request.'); } $output = &mt('Your request for self-enrollment has been recorded.').'
'. - &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'
'; + &mt('A message will be sent to your LON-CAPA account when the course 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".'); my %emails = &Apache::loncommon::getemails($uname,$udom); if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) { my $address = $emails{'permanentemail'}; @@ -574,13 +576,16 @@ sub store_selfenroll_request { if ($warning) { $output .= ''.$warning.'
'; } - + + $output .= '
'.&Apache::loncoursequeueadmin::queued_selfenrollment(); + if ($selfenroll_notifylist) { my $fullname = &Apache::loncommon::plainname($uname,$udom); my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); my $coursedesc = $courseinfo{'description'}; - &send_notification($selfenroll_notifylist,$fullname,$cdom. - '_'.$cnum,$coursedesc,$now,'request',$owner); + &Apache::loncoursequeueadmin::send_selfserve_notification( + $selfenroll_notifylist,$fullname,$cdom.'_'.$cnum, + $coursedesc,$now,'selfenrollreq',$owner); } } else { $output = ''.&mt('An error occurred when recording your request.').''; @@ -590,104 +595,6 @@ sub store_selfenroll_request { return $output; } -sub send_notification { - my ($notifylist,$textstr,$cid,$coursedesc,$timestamp,$context,$sender, - $approvedlist,$rejectedlist) = @_; -# 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,$namelink); - $namelink = &Apache::loncommon::aboutmewrapper( - &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})); - if ($context eq 'managers') { - $rawsubj = 'Self-enrollment requests processed'; - push(@rawmsg,{ - mt => 'Enrollment requests in the following course: [_1] have been processed.', - args => ["\n$coursedesc\n"], - }); - } elsif ($context eq 'enroller') { - $rawsubj = 'Enrollment request'; - push(@rawmsg,{ - mt => 'Your request for enrollment in the following course: [_1], requested on [_2], has been reviewed by a Course Coordinator.', - args => ["\n$coursedesc\n","$timestamp\n"], - - }); - if (ref($textstr) eq 'ARRAY') { - push(@rawmsg,@{$textstr}); - } - } else { - $rawsubj = 'Self-enrollment request'; - push(@rawmsg,{ - mt => 'Enrollment in the following course: [_1] was requested by [_2] on [_3].', - args => ["\n$coursedesc\n",$textstr,$timestamp], - }, - { - mt =>'As Course Coordinator, use: [_1]Main Menu -> Manage Couse Users -> Enrollment Requests[_1] to display a list of pending enrollment requests,[_1] which you can either approve or reject.', - args => ["\n"], - }); - } - my @to_notify = split(/,/,$notifylist); - my $numsent = 0; - my @recusers; - my @recudoms; - foreach my $cc (@to_notify) { - my ($ccname,$ccdom) = split(/:/,$cc); - if (!exists($msgcc->{$ccname.':'.$ccdom})) { - push(@recusers,$ccname); - push(@recudoms,$ccdom); - $msgcc->{$ccname.':'.$ccdom}=''; - $numsent ++; - } - } - my %reciphash = ( - cc => $msgcc, - ); - my ($uname,$udom); - if ($sender =~ /:/) { - ($uname,$udom) = split(/:/,$sender); - } else { - $uname = $sender; - my %courseinfo = &Apache::lonnet::coursedescription($cid); - $udom = $courseinfo{'num'}; - } - my %sentmessage; - my $stamp = time; - my $msgcount = &Apache::lonmsg::get_uniq(); - my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid); - $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj); - $message = ''; - foreach my $item (@rawmsg) { - if (ref($item) eq 'HASH') { - $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); - my ($recipid,$recipstatus) = - &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash); - foreach my $recip (sort(keys(%{$msgcc}))) { - my ($ccname,$ccdom) = split(/:/,$recip); - my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid); - my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj); - my $message = ''; - foreach my $item (@rawmsg) { - if (ref($item) eq 'HASH') { - $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt}, - @{$item->{args}})."\n"; - } - } - if ($context eq 'managers') { - if ($approvedlist) { - $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist; - } - if ($rejectedlist) { - $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist; - } - } - my $status = &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid); - } -} - sub jump_to_role { my ($role) = @_; my $output = <<"END";