File:  [LON-CAPA] / loncom / interface / loncoursequeueadmin.pm
Revision 1.1: download - view: text, annotated - select for diffs
Tue Aug 11 00:39:45 2009 UTC (14 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Course requests.
- Moving and modifying some routines used for displaying queues (oringinally created for approval/rejection of self-enroll requests to also support approval/rejection of course creation requests.
   - &display_selfenroll_queue() moved from loncreateuser.pm to loncoursequeueadmin.pm
      (and renamed &display_queued_requests() ).
   - &update_selfenroll_queue() moved from loncreateuser.pm to loncoursequeueadmin.pm
      (and renamed &update_request_queue() ).
   - &get_student_counts() moved from loncreateuser.pm to loncoursequeueadmin.pm

   - &send_notification() moved from selfenroll.pm to loncoursequeueadmin.pm
      (and renamed &send_selfserver_notification() ).

    1: # The LearningOnline Network
    2: # Utilities to administer domain course requests and course self-enroll requests 
    3: #
    4: # $Id: loncoursequeueadmin.pm,v 1.1 2009/08/11 00:39:45 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: =head1 NAME
   31: 
   32: Apache::loncoursequeueadmin.pm
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Adminitsration utilities used by domain coordinators for queued course creation requests, and by course coordinators for queued self-enrollment requests.
   37: 
   38: This is part of the LearningOnline Network with CAPA project
   39: described at http://www.lon-capa.org.
   40: 
   41: =head1 SUBROUTINES
   42: 
   43: =over
   44: 
   45: =item send_selfserve_notification()
   46: 
   47: =item display_queued_requests()
   48: 
   49: =item update_request_queue()
   50: 
   51: =item get_student_counts()
   52: 
   53: =back
   54: 
   55: =cut
   56: 
   57: package Apache::loncoursequeueadmin;
   58: 
   59: use strict;
   60: use Apache::Constants qw(:common :http);
   61: use Apache::lonnet;
   62: use Apache::loncommon;
   63: use Apache::lonmsg;
   64: use Apache::lonlocal;
   65: use LONCAPA;
   66: 
   67: sub send_selfserve_notification {
   68:     my ($notifylist,$textstr,$cid,$coursedesc,$timestamp,$context,$sender,
   69:         $approvedlist,$rejectedlist) = @_;
   70: # FIXME locallocaltime needs to be able to take $sender_lh as an argument
   71: #       so this can be localized to the recipients date display format/time zone
   72:     $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
   73:     my $msgcc;
   74:     my ($rawsubj,@rawmsg,$subject,$message,$namelink);
   75:     $namelink = &Apache::loncommon::aboutmewrapper(
   76:                 &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}));
   77:     if ($context eq 'coursemanagers') {
   78:         $rawsubj = 'Self-enrollment requests processed';
   79:         push(@rawmsg,{
   80:                       mt => 'Enrollment requests in the following course: [_1] have been processed.',
   81:                       args => ["\n$coursedesc\n"],
   82:                      });
   83:     } elsif ($context eq 'domainmanagers') {
   84:         $rawsubj = 'Course request';
   85:         push(@rawmsg,{
   86:                       mt  => 'Your request for creation of the following course: [_1], requested on [_2], has been reviewed by a Domain Coordinator.',
   87:                       args => ["\n$coursedesc\n","$timestamp\n"],
   88: 
   89:                      });
   90:         if (ref($textstr) eq 'ARRAY') {
   91:             push(@rawmsg,@{$textstr});
   92:         }
   93:     } elsif ($context eq 'enroller') {
   94:         $rawsubj = 'Enrollment request';
   95:         push(@rawmsg,{
   96:                       mt  => 'Your request for enrollment in the following course: [_1], requested on [_2], has been reviewed by a Course Coordinator.',
   97:                       args => ["\n$coursedesc\n","$timestamp\n"],
   98: 
   99:                      });
  100:         if (ref($textstr) eq 'ARRAY') {
  101:             push(@rawmsg,@{$textstr});
  102:         }
  103:     } elsif ($context eq 'courserequestor') {
  104:         $rawsubj = 'Course request';
  105:         push(@rawmsg,{
  106:                       mt  => 'Your request for creation of the following course: [_1], requested on [_2], has been reviewed by a Domain Coordinator.',
  107:                       args => ["\n$coursedesc\n","$timestamp\n"],
  108: 
  109:                      });
  110:         if (ref($textstr) eq 'ARRAY') {
  111:             push(@rawmsg,@{$textstr});
  112:         }
  113:     } elsif ($context eq 'coursereq') {
  114:         push(@rawmsg,{
  115:                       mt  => 'Creation of the following course: [_1] was requested by [_2] on [_3].',
  116:                       args => ["\n$coursedesc\n",$textstr,$timestamp],
  117:                      },
  118:                      {
  119:                       mt =>'As Domain Coordinator, use: [_1]Main Menu -> Create a new course -> Manage Course Requests[_1] to display a list of pending course requests,[_1] which you can either approve or reject.',
  120:                       args => ["\n"],
  121:                      });
  122:     } elsif ($context eq 'selfenrollreq') {
  123:         $rawsubj = 'Self-enrollment request';
  124:         push(@rawmsg,{
  125:                       mt  => 'Enrollment in the following course: [_1] was requested by [_2] on [_3].',
  126:                       args => ["\n$coursedesc\n",$textstr,$timestamp],
  127:                      },
  128:                      {
  129:                       mt =>'As Course Coordinator, use: [_1]Main Menu -> Manage Course Users -> Enrollment Requests[_1] to display a list of pending enrollment requests,[_1] which you can either approve or reject.',
  130:                       args => ["\n"],
  131:                      });
  132:     }
  133:     my @to_notify = split(/,/,$notifylist);
  134:     my $numsent = 0;
  135:     my @recusers;
  136:     my @recudoms;
  137:     foreach my $cc (@to_notify) {
  138:         my ($ccname,$ccdom) = split(/:/,$cc);
  139:         if (!exists($msgcc->{$ccname.':'.$ccdom})) {
  140:             push(@recusers,$ccname);
  141:             push(@recudoms,$ccdom);
  142:             $msgcc->{$ccname.':'.$ccdom}='';
  143:             $numsent ++;
  144:         }
  145:     }
  146:     my %reciphash = (
  147:                      cc => $msgcc,
  148:     );
  149:     my ($uname,$udom);
  150:     if ($sender =~ /:/) {
  151:         ($uname,$udom) = split(/:/,$sender);
  152:     } else {
  153:         $uname = $sender;
  154:         my %courseinfo = &Apache::lonnet::coursedescription($cid);
  155:         $udom = $courseinfo{'num'};
  156:     }
  157:     my %sentmessage;
  158:     my $stamp = time;
  159:     my $msgcount = &Apache::lonmsg::get_uniq();
  160:     my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
  161:     $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
  162:     $message = '';
  163:     foreach my $item (@rawmsg) {
  164:         if (ref($item) eq 'HASH') {
  165:             $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
  166:         }
  167:     }
  168:     &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms);
  169:     my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
  170:     my $status;
  171:     foreach my $recip (sort(keys(%{$msgcc}))) {
  172:         my ($ccname,$ccdom) = split(/:/,$recip);
  173:         my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
  174:         my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
  175:         my $message = '';
  176:         foreach my $item (@rawmsg) {
  177:             if (ref($item) eq 'HASH') {
  178:                 $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},
  179:                                                        @{$item->{args}})."\n";
  180:             }
  181:         }
  182:         if ($context eq 'managers') {
  183:             if ($approvedlist) {
  184:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
  185:             }
  186:             if ($rejectedlist) {
  187:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
  188:             }
  189:         } elsif ($context eq 'domainmanagers') {
  190:             if ($approvedlist) {
  191:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
  192:             }
  193:             if ($rejectedlist) {
  194:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
  195:             }
  196:         }
  197:         $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
  198:     }
  199:     $status =~ s/,$//;
  200:     return ($recipstatus,$status);
  201: }
  202: 
  203: sub display_queued_requests {
  204:     my ($context,$dom,$cnum) = @_;
  205:     my ($namespace,$formaction,%requesthash);
  206:     if ($context eq 'course') {
  207:         $formaction = '/adm/createuser';
  208:         $namespace = 'selfenrollrequests';
  209:         %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
  210:     } else {
  211:         $formaction = '/adm/createcourse';
  212:         $namespace = 'courserequestqueue';
  213:         %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,undef,'_approval');
  214:     }
  215:     my ($output,%queue_by_date,%crstypes);
  216:     if (keys(%requesthash) > 0) {
  217:         $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'.
  218:                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
  219:                   '<input type="hidden" name="state" value="done" />'.
  220:                   &Apache::loncommon::start_data_table().
  221:                   &Apache::loncommon::start_data_table_header_row().
  222:                   '<th>'.&mt('Action').'</th>'.
  223:                   '<th>'.&mt('Requestor').'</th>';
  224:         if ($context eq 'course') {
  225:             $output .= '<th>'.&mt('Section').'</th>'.
  226:                        '<th>'.&mt('Date requested').'</th>';
  227:             %crstypes = &Apache::lonlocal::texthash (
  228:                             official   => 'Official course',
  229:                             unofficial => 'Unofficial course',
  230:                             community  => 'Community',
  231:                         );
  232:         } else {
  233:             $output .= '<th>'.&mt('Type').'</th>'.
  234:                        '<th>'.&mt('Date requested').'</th>'.
  235:                        '<th>'.&mt('Details').'</th>';
  236:         }
  237:         $output .= &Apache::loncommon::end_data_table_header_row();
  238:         foreach my $item (keys(%requesthash)) {
  239:             my ($timestamp,$entry);
  240:             if ($context eq 'course') {
  241:                 ($timestamp, my $usec) = split(/:/,$requesthash{$item});
  242:                 $entry = $item.':'.$usec;
  243:             } else {
  244:                 $timestamp = $requesthash{$item}{'timestamp'};
  245:                 if (ref($requesthash{$item}) eq 'HASH') {
  246:                     $entry = $item.':'.$requesthash{$item}{'ownername'}.':'.
  247:                              $requesthash{$item}{'ownerdom'}.':'.
  248:                              $requesthash{$item}{'crstype'}.':'.
  249:                              $requesthash{$item}{'description'};
  250:                 }
  251:             }
  252:             if ($entry ne '') {
  253:                 if (exists($queue_by_date{$timestamp})) {
  254:                     if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
  255:                         push(@{$queue_by_date{$timestamp}},$entry);
  256:                     }
  257:                 } else {
  258:                     @{$queue_by_date{$timestamp}} = ($entry);
  259:                 }
  260:             }
  261:         }
  262:         my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
  263:         my $count = 0;
  264:         foreach my $item (@sortedtimes) {
  265:             if (ref($queue_by_date{$item}) eq 'ARRAY') {
  266:                 foreach my $request (sort(@{$queue_by_date{$item}})) {
  267:                     my ($row,$approve,$reject,$showtime,$showsec,$namelink,
  268:                         $detailslink,$crstype);
  269:                     $showtime = &Apache::lonlocal::locallocaltime($item);
  270:                     if ($context eq 'course') {
  271:                         my ($puname,$pudom,$pusec) = split(/:/,$request);
  272:                         $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
  273:                         $reject = $puname.':'.$pudom;
  274:                         $showsec = $pusec;
  275:                         if ($showsec eq '') {
  276:                             $showsec = &mt('none');
  277:                         }
  278:                         $namelink = &Apache::loncommon::aboutmewrapper(
  279:                                     &Apache::loncommon::plainname($puname,$pudom),
  280:                                     $puname,$pudom);
  281: 
  282:                     } else {
  283:                         my ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request);
  284:                         $detailslink='<a href="javascript::opencoursereqdisplay('.
  285:                                       "'$dom".'_'."$cnum'".');">'.$cdesc.'</a>';
  286:                         $crstype = $type;
  287:                         if (defined($crstypes{$type})) {
  288:                             $crstype = $crstypes{$type};
  289:                         }
  290:                         $approve = $count.':'.$cnum;
  291:                         $reject = $cnum;
  292:                         $namelink = &Apache::loncommon::aboutmewrapper(
  293:                                     &Apache::loncommon::plainname($ownername,$ownerdom),
  294:                                     $ownername,$ownerdom);
  295:                     }
  296:                     $row = '<td><span class="LC_nobreak"><label>'.
  297:                            '<input type="checkbox" value="'.$approve.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
  298:                            '<span class="LC_nobreak"><label>'.
  299:                            '<input type="checkbox" value="'.$reject.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
  300:                            '<td>'.$namelink.'</td>'."\n";
  301:                     if ($context eq 'course') {
  302:                         $row .= '<td>'.$showsec.'</td>'."\n".
  303:                                 '<td>'.$showtime.'</td>'."\n";
  304:                     } else { 
  305:                         $row .= '<td>'.$crstype.'</td>'."\n".
  306:                                 '<td>'.$showtime.'</td>'."\n".
  307:                                 '<td>'.$detailslink.'</td>'."\n";
  308:                     }
  309:                     $output .= &Apache::loncommon::start_data_table_row()."\n".
  310:                                $row.
  311:                                &Apache::loncommon::end_data_table_row()."\n";
  312:                     $count ++;
  313:                 }
  314:             }
  315:         }
  316:         $output .= &Apache::loncommon::end_data_table().
  317:                    '<input type="submit" name="processqueue" value="'.&mt('Save').
  318:                    '" /></form>';
  319:     } else {
  320:         if ($context eq 'course') {
  321:             $output .= &mt('There are currently no enrollment requests.');
  322:         } else {
  323:             $output .= &mt('There are currently no course requests awaiting approval.');
  324:         }
  325:     }
  326:     return $output;
  327: }
  328: 
  329: sub update_request_queue {
  330:     my ($context,$cdom,$cnum,$coursedesc) = @_;
  331:     my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
  332:         $stucounts,$idx,$classlist,%requesthash,$coursedesc,$cid,$hostname,
  333:         $protocol,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
  334:         @existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,@created,
  335:         @enrollerrors,@create_errors,@warn_approves,@warn_rejects,@approvals,
  336:         @rejections);
  337:     @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
  338:     @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
  339:     $now = time;
  340:     $sender = $env{'user.name'}.':'.$env{'user.domain'};
  341:     if ($context eq 'course') {
  342:         $namespace = 'selfenrollrequests';
  343:         $beneficiary = 'enroller';
  344:         $cid = $env{'request.course.id'};
  345:         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
  346:         $hostname = &Apache::lonnet::hostname($chome);
  347:         $protocol = $Apache::lonnet::protocol{$chome};
  348:         $protocol = 'http' if ($protocol ne 'https');
  349:         %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
  350:         $access_start =  $env{'course.'.$cid.'.internal.selfenroll_start_access'};
  351:         $access_end =  $env{'course.'.$cid.'.internal.selfenroll_end_access'};
  352:         $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
  353:         $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
  354:         $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
  355:         $namespace = 'selfenrollrequests';
  356:         ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
  357:         $approvedmsg = [{
  358:                             mt => 'Your request for enrollment has been approved.',
  359:                         },
  360:                         {
  361:                             mt   => 'Visit [_1], to log-in and access the course',
  362:                             args => [$protocol.'://'.$hostname],
  363:                         }];
  364:         $rejectedmsg =  [{
  365:                             mt => 'Your request for enrollment has not been approved.',
  366:                         }];
  367:     } else {
  368:         $beneficiary = 'requestor';
  369:     }
  370:     foreach my $item (sort {$a <=> $b} @approvals) {
  371:         if ($context eq 'course') {
  372:             my ($num,$uname,$udom,$usec) = split(/:/,$item);
  373:             my $uhome = &Apache::lonnet::homeserver($uname,$udom);
  374:             if ($uhome ne 'no_host') {
  375:                 if (exists($requesthash{$uname.':'.$udom})) {
  376: 
  377:                     if (exists($classlist->{$uname.':'.$udom})) {
  378:                         if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
  379:                             if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
  380:                                 ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
  381:                                 push(@existing,$uname.':'.$udom);
  382:                                 next;
  383:                             }
  384:                         }
  385:                     }
  386:                 } else {
  387:                     push(@missingreq,$uname.':'.$udom);
  388:                     next;
  389:                 }
  390:                 if (!grep(/^\Q$item\E$/,@rejections)) {
  391:                     if ($limit eq 'allstudents') {
  392:                         if ($stucounts->{$limit} >= $cap) {
  393:                             push(@limitexceeded,$uname.':'.$udom);
  394:                             last;
  395:                         }
  396:                     } elsif ($limit eq 'selfenrolled') {
  397:                         if ($stucounts->{$limit} >= $cap) {
  398:                             push(@limitexceeded,$uname.':'.$udom);
  399:                             last;
  400:                         }
  401:                     }
  402:                     my $result =
  403:                         &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
  404:                     if ($result eq 'ok') {
  405:                         push(@enrolled,$uname.':'.$udom);
  406:                         $stucounts->{'allstudents'} ++;
  407:                         $stucounts->{'selfenrolled'} ++;
  408:                         &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
  409:                                        $cid,$coursedesc,$now,$beneficiary,$sender);
  410:                         my %userrequest;
  411:                         if ($context eq 'course') {
  412:                             %userrequest = (
  413:                                 $cdom.'_'.$cnum => {
  414:                                     timestamp   => $now,
  415:                                     section     => $usec,
  416:                                     adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
  417:                                     status      => 'approved',
  418:                                 }
  419:                             );
  420:                         } else {
  421:                             %userrequest = ();
  422:                         }
  423:                         my $userresult =
  424:                             &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
  425:                         if ($userresult ne 'ok') {
  426:                             push(@warn_approves,$uname.':'.$udom);
  427:                         }
  428:                     } else {
  429:                         push(@enrollerrors,$uname.':'.$udom);
  430:                     }
  431:                 }
  432:             } else {
  433:                 push(@invalidusers,$uname.':'.$udom);
  434:             }
  435:         } else {
  436: 
  437:         }
  438:     }
  439:     my @changes = (@enrolled,@rejections);
  440:     if (@rejections) {
  441:         foreach my $user (@rejections) {
  442:             &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
  443:                                          $now,$beneficiary,$sender);
  444:             if ($context eq 'course') {
  445:                 my ($uname,$udom) = split(/:/,$user);
  446:                 my %userrequest = (
  447:                     $cdom.'_'.$cnum => {
  448:                         timestamp   => $now,
  449:                         adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
  450:                         status      => 'rejected',
  451:                     }
  452:                 );
  453:                 my $userresult =
  454:                     &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
  455:                 if ($userresult ne 'ok') {
  456:                     push(@warn_rejects,$user);
  457:                 }
  458:             } else {
  459: 
  460:             }
  461:         }
  462:     }
  463:     if (@changes) {
  464:         my $delresult;
  465:         if ($context eq 'course') {
  466:             $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
  467:         } else {
  468:             $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
  469:         }
  470:         if ($delresult eq 'ok') {
  471:             my $namelink =
  472:                 &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
  473:             my ($chgmsg,$approvedlist,$rejectedlist);
  474:             if ($context eq 'course') {
  475:                 $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
  476:                 if (@enrolled) {
  477:                     $approvedlist = join("\n",@enrolled);
  478:                     $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
  479:                     foreach my $user (@enrolled) {
  480:                         my ($uname,$udom) = split(/:/,$user);
  481:                         my $userlink =
  482:                             &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
  483:                         $output .= '<li>'.$userlink.'</li>';
  484:                     }
  485:                     $output .= '</ul></p>';
  486:                 }
  487:                 if (@rejections) {
  488:                     $rejectedlist = join("\n",@rejections);
  489:                     $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
  490:                     foreach my $user (@rejections) {
  491:                         $output .= '<li>'.$user.'</li>';
  492:                     }
  493:                     $output .= '</ul></p>';
  494:                 }
  495:             } else {
  496: 
  497: 
  498:             }
  499:             &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
  500:                                          $now,'coursemanagers',$sender,
  501:                                          $approvedlist,$rejectedlist);
  502:         }
  503:     }
  504:     if (@existing) {
  505:         if ($context eq 'course') {
  506:             $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
  507:             foreach my $user (@existing) {
  508:                 $output .= '<li>'.$user.'</li>';
  509:             }
  510:             $output .= '</ul></p>';
  511:         } else {
  512: 
  513:         }
  514:     }
  515:     if (@missingreq) {
  516:         if ($context eq 'course') {
  517:             $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
  518:             foreach my $user (@missingreq) {
  519:                 $output .= '<li>'.$user.'</li>';
  520:             }
  521:             $output .= '</ul></p>';
  522:         }
  523:     }
  524:     if (@invalidusers) {
  525:         if ($context eq 'course') {
  526:             $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
  527:             foreach my $user (@invalidusers) {
  528:                 $output .= '<li>'.$user.'</li>';
  529:             }
  530:             $output .= '</ul></p>';
  531:         } else {
  532: 
  533:         }
  534:     }
  535:     if (@limitexceeded) {
  536:         if ($context eq 'course') {
  537:             $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
  538:             foreach my $user (@limitexceeded) {
  539:                 $output .= '<li>'.$user.'</li>';
  540:             }
  541:             $output .= '</ul></p>';
  542:         } else {
  543: 
  544:         }
  545:     }
  546:     if (@enrollerrors) {
  547:         if ($context eq 'course') {
  548:             $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
  549:             foreach my $user (@enrollerrors) {
  550:                 $output .= '<li>'.$user.'</li>';
  551:             }
  552:             $output .= '</ul></p>';
  553:         } else {
  554: 
  555:         }
  556:     }
  557:     if (@warn_approves) {
  558:         if ($context eq 'course') {
  559:             $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
  560:             foreach my $user (@warn_approves) {
  561:                 $output .= '<li>'.$user.'</li>';
  562:             }
  563:             $output .= '</ul></p>';
  564:         } else {
  565: 
  566:         }
  567:     }
  568:     if (@warn_rejects) {
  569:         if ($context eq 'course') {
  570:             $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
  571:             foreach my $user (@warn_rejects) {
  572:                 $output .= '<li>'.$user.'</li>';
  573:             }
  574:             $output .= '</ul></p>';
  575:         } else {
  576: 
  577:         }
  578:     }
  579:     return $output;
  580: }
  581: 
  582: sub get_student_counts {
  583:     my ($cdom,$cnum) = @_;
  584:     my (%idx,%stucounts);
  585:     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
  586:     $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
  587:     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
  588:     while (my ($student,$data) = each(%$classlist)) {
  589:         if (($data->[$idx{'status'}] eq 'Active') ||
  590:             ($data->[$idx{'status'}] eq 'Future')) {
  591:             if ($data->[$idx{'type'}] eq 'selfenroll') {
  592:                 $stucounts{'selfenroll'} ++;
  593:             }
  594:             $stucounts{'allstudents'} ++;
  595:         }
  596:     }
  597:     return (\%stucounts,\%idx,$classlist);
  598: }
  599: 
  600: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>