File:  [LON-CAPA] / loncom / interface / loncoursequeueadmin.pm
Revision 1.12.2.1: download - view: text, annotated - select for diffs
Mon Dec 7 02:04:25 2009 UTC (14 years, 5 months ago) by raeburn
Branches: GCI_3
- Customization for GCI. (same change as in 1.9.2.1 and 1.9.2.2 for GCI_2).
   - Users for whom self-enrollment is approved in the GCI Concept Inventory, automatically receive the right to create unlimited Concept Test courses in the gcitest domain.

    1: # The LearningOnline Network
    2: # Utilities to administer domain course requests and course self-enroll requests 
    3: #
    4: # $Id: loncoursequeueadmin.pm,v 1.12.2.1 2009/12/07 02:04:25 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 Apache::lonuserutils;
   66: use LONCAPA;
   67: 
   68: sub send_selfserve_notification {
   69:     my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender,
   70:         $approvedlist,$rejectedlist,$crstype) = @_;
   71: # FIXME locallocaltime needs to be able to take $sender_lh as an argument
   72: #       so this can be localized to the recipients date display format/time zone
   73:     $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
   74:     my $msgcc;
   75:     my ($rawsubj,@rawmsg,$subject,$message,$reviewer,$msgtxt);
   76:     if ($context eq 'coursemanagers') {
   77:         $rawsubj = 'Self-enrollment requests processed';
   78:         push(@rawmsg,{
   79:                       mt => 'Enrollment requests in the following course: [_1] have been processed.',
   80:                       args => ["\n  $contextdesc"],
   81:                      });
   82:     } elsif ($context eq 'domainmanagers') {
   83:         $rawsubj = 'Course/Community requests reviewed';
   84:         push(@rawmsg,{
   85:                       mt  => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
   86:                       args => ["\n  $contextdesc"],
   87:                      });
   88:         if (ref($textstr) eq 'ARRAY') {
   89:             push(@rawmsg,@{$textstr});
   90:         }
   91:     } elsif ($context eq 'enroller') {
   92:         $rawsubj = 'Enrollment request';
   93:         if ($crstype eq 'community') {
   94:             $msgtxt = 'Your request for enrollment in the following community: [_1]requested on [_2]has been reviewed by a Coordinator.'
   95:         } else {
   96:             $msgtxt = 'Your request for enrollment in the following course: [_1]requested on [_2]has been reviewed by a Course Coordinator.';
   97:         } 
   98:         push(@rawmsg,{
   99:                       mt  => $msgtxt,
  100:                       args => ["\n  ".$contextdesc.",\n",$timestamp.",\n"],
  101: 
  102:                      });
  103:         if (ref($textstr) eq 'ARRAY') {
  104:             push(@rawmsg,@{$textstr});
  105:         }
  106:     } elsif ($context eq 'courserequestor') {
  107:         if ($crstype eq 'Community') {
  108:             $rawsubj = 'Community request';
  109:             $msgtxt = 'Your request for creation of the following community: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
  110:         } else {
  111:             $rawsubj = 'Course request';
  112:             $msgtxt = 'Your request for creation of the following course: [_1]requested on [_2]has been reviewed by a Domain Coordinator.';
  113:         }
  114:         push(@rawmsg,{
  115:                       mt  => $msgtxt,
  116:                       args => ["\n".$contextdesc.",\n",$timestamp.",\n"],
  117: 
  118:                      });
  119:         if (ref($textstr) eq 'ARRAY') {
  120:             push(@rawmsg,@{$textstr});
  121:         }
  122:     } elsif ($context eq 'coursereq') {
  123:         if ($crstype eq 'community') {
  124:             $rawsubj = 'Community request to review';
  125:             $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
  126:         } else {
  127:             $rawsubj = 'Course request to review';
  128:             $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
  129:         }
  130:         push(@rawmsg,{
  131:                       mt  => $msgtxt,
  132:                       args => ["\n  $contextdesc\n",$textstr,$timestamp],
  133:                      },
  134:                      {
  135:                       mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',
  136:                       args => ["\n","\n\n  ","\n\n"],
  137:                      });
  138:     } elsif ($context eq 'selfenrollreq') {
  139:         $rawsubj = 'Self-enrollment request';
  140:         if ($crstype eq 'community') {
  141:             $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'
  142:         } else {
  143:             $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'
  144:         }
  145:         push(@rawmsg,{
  146:                       mt  => $msgtxt,
  147:                       args => ["\n  $contextdesc\n",$textstr,$timestamp."\n"],
  148:                      });
  149:         my $directions;  
  150:         if ($crstype eq 'community') {
  151:             $directions = 'As Coordinator, use: [_1]Main Menu -> Manage Community Users -> Enrollment Requests[_2]to display a list of pending enrollment requests, which you can either approve or reject.';
  152:         } else {
  153:             $directions = 'As Course Coordinator, use: [_1]Main Menu -> Manage Course Users -> Enrollment Requests[_2]to display a list of pending enrollment requests, which you can either approve or reject.';
  154:         }
  155:         push(@rawmsg,
  156:                      {
  157:                       mt   => $directions,
  158:                       args => ["  \n\n","\n"],
  159:                      });
  160: 
  161:     }
  162:     my @to_notify = split(/,/,$notifylist);
  163:     my $numsent = 0;
  164:     my @recusers;
  165:     my @recudoms;
  166:     foreach my $cc (@to_notify) {
  167:         my ($ccname,$ccdom) = split(/:/,$cc);
  168:         if (!exists($msgcc->{$ccname.':'.$ccdom})) {
  169:             push(@recusers,$ccname);
  170:             push(@recudoms,$ccdom);
  171:             $msgcc->{$ccname.':'.$ccdom}='';
  172:             $numsent ++;
  173:         }
  174:     }
  175:     my %reciphash = (
  176:                      cc => $msgcc,
  177:     );
  178:     my ($uname,$udom);
  179:     if ($sender =~ /:/) {
  180:         ($uname,$udom) = split(/:/,$sender);
  181:     } elsif ($context eq 'course') {
  182:         $uname = $sender;
  183:         my %courseinfo = &Apache::lonnet::coursedescription($cid);
  184:         $udom = $courseinfo{'num'};
  185:     }
  186:     my %sentmessage;
  187:     my $stamp = time;
  188:     my $msgcount = &Apache::lonmsg::get_uniq();
  189:     my $sender_lh = &Apache::loncommon::user_lang($uname,$udom,$cid);
  190:     $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
  191:     $message = '';
  192:     foreach my $item (@rawmsg) {
  193:         if (ref($item) eq 'HASH') {
  194:             $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
  195:         }
  196:     }
  197:     &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,\@recusers,\@recudoms);
  198:     my ($recipid,$recipstatus) = &Apache::lonmsg::store_recipients($subject,$uname,$udom,\%reciphash);
  199:     my $status;
  200:     foreach my $recip (sort(keys(%{$msgcc}))) {
  201:         my ($ccname,$ccdom) = split(/:/,$recip);
  202:         my $recip_lh = &Apache::loncommon::user_lang($ccname,$ccdom,$cid);
  203:         my $subject = &Apache::lonlocal::mt_user($sender_lh,$rawsubj);
  204:         my $message = '';
  205:         foreach my $item (@rawmsg) {
  206:             if (ref($item) eq 'HASH') {
  207:                 $message .= &Apache::lonlocal::mt_user($sender_lh,$item->{mt},
  208:                                                        @{$item->{args}})."\n";
  209:             }
  210:         }
  211:         if ($context eq 'coursemanagers') {
  212:             if ($approvedlist) {
  213:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved enrollments:')."\n".$approvedlist;
  214:             }
  215:             if ($rejectedlist) {
  216:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected enrollments:')."\n".$rejectedlist;
  217:             }
  218:         } elsif ($context eq 'domainmanagers') {
  219:             if ($approvedlist) {
  220:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Approved course requests:')."\n".$approvedlist;
  221:             }
  222:             if ($rejectedlist) {
  223:                 $message .= "\n\n".&Apache::lonlocal::mt_user($sender_lh,'Rejected course requests:')."\n".$rejectedlist;
  224:             }
  225:         }
  226:         $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,\%sentmessage,undef,undef,undef,1,$recipid).',';
  227:     }
  228:     $status =~ s/,$//;
  229:     return ($recipstatus,$status);
  230: }
  231: 
  232: sub display_queued_requests {
  233:     my ($context,$dom,$cnum) = @_;
  234:     my ($namespace,$formaction,$nextelement,%requesthash);
  235:     if ($context eq 'course') {
  236:         $formaction = '/adm/createuser';
  237:         $namespace = 'selfenrollrequests';
  238:         %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
  239:         $nextelement = '<input type="hidden" name="state" value="done" />';
  240:     } else {
  241:         $formaction = '/adm/createcourse';
  242:         $namespace = 'courserequestqueue';
  243:         %requesthash = &Apache::lonnet::dump_dom($namespace,$dom,'_approval');
  244:         $nextelement = '<input type="hidden" name="phase" value="requestchange" />';
  245:     }
  246:     my ($output,%queue_by_date,%crstypes);
  247:     if (keys(%requesthash) > 0) {
  248:         $output = '<form method="post" name="changequeue" action="'.$formaction.'" />'."\n".
  249:                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
  250:                   $nextelement."\n".
  251:                   &Apache::loncommon::start_data_table().
  252:                   &Apache::loncommon::start_data_table_header_row().
  253:                   '<th>'.&mt('Action').'</th>'.
  254:                   '<th>'.&mt('Requestor').'</th>';
  255:         if ($context eq 'course') {
  256:             $output .= '<th>'.&mt('Section').'</th>'.
  257:                        '<th>'.&mt('Date requested').'</th>';
  258:         } else {
  259:             %crstypes = &Apache::lonlocal::texthash (
  260:                             official   => 'Official course',
  261:                             unofficial => 'Unofficial course',
  262:                             community  => 'Community',
  263:                         );
  264:             $output .= '<th>'.&mt('Type').'</th>'.
  265:                        '<th>'.&mt('Date requested').'</th>'.
  266:                        '<th>'.&mt('Details').'</th>';
  267:         }
  268:         $output .= &Apache::loncommon::end_data_table_header_row();
  269:         foreach my $item (keys(%requesthash)) {
  270:             my ($timestamp,$entry);
  271:             if ($context eq 'course') {
  272:                 ($timestamp, my $usec) = split(/:/,$requesthash{$item});
  273:                 $entry = $item.':'.$usec;
  274:             } else {
  275:                 $timestamp = $requesthash{$item}{'timestamp'};
  276:                 if (ref($requesthash{$item}) eq 'HASH') {
  277:                     my ($cnum,$disposition) = split('_',$item);
  278:                     $entry = $cnum.':'.$requesthash{$item}{'ownername'}.':'.
  279:                              $requesthash{$item}{'ownerdom'}.':'.
  280:                              $requesthash{$item}{'crstype'}.':'.
  281:                              $requesthash{$item}{'description'};
  282:                 }
  283:             }
  284:             if ($entry ne '') {
  285:                 if (exists($queue_by_date{$timestamp})) {
  286:                     if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
  287:                         push(@{$queue_by_date{$timestamp}},$entry);
  288:                     }
  289:                 } else {
  290:                     @{$queue_by_date{$timestamp}} = ($entry);
  291:                 }
  292:             }
  293:         }
  294:         my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
  295:         my $count = 0;
  296:         foreach my $item (@sortedtimes) {
  297:             if (ref($queue_by_date{$item}) eq 'ARRAY') {
  298:                 foreach my $request (sort(@{$queue_by_date{$item}})) {
  299:                     my ($row,$approve,$reject,$showtime,$showsec,$namelink,
  300:                         $detailslink,$crstype);
  301:                     $showtime = &Apache::lonlocal::locallocaltime($item);
  302:                     if ($context eq 'course') {
  303:                         my ($puname,$pudom,$pusec) = split(/:/,$request);
  304:                         $approve = $count.':'.$puname.':'.$pudom.':'.$pusec;
  305:                         $reject = $puname.':'.$pudom;
  306:                         $showsec = $pusec;
  307:                         if ($showsec eq '') {
  308:                             $showsec = &mt('none');
  309:                         }
  310:                         $namelink = &Apache::loncommon::aboutmewrapper(
  311:                                     &Apache::loncommon::plainname($puname,$pudom),
  312:                                     $puname,$pudom);
  313: 
  314:                     } else {
  315:                         my ($cnum,$ownername,$ownerdom,$type,$cdesc)=split(/:/,$request,5);
  316:                         $detailslink='<a href="javascript:opencoursereqdisplay('.
  317:                                       "'$dom','$cnum'".');">'.$cdesc.'</a>';
  318:                         $crstype = $type;
  319:                         if (defined($crstypes{$type})) {
  320:                             $crstype = $crstypes{$type};
  321:                         }
  322:                         $approve = $count.':'.$cnum;
  323:                         $reject = $cnum;
  324:                         $namelink = &Apache::loncommon::aboutmewrapper(
  325:                                     &Apache::loncommon::plainname($ownername,$ownerdom),
  326:                                     $ownername,$ownerdom);
  327:                     }
  328:                     $row = '<td><span class="LC_nobreak"><label>'.
  329:                            '<input type="checkbox" value="'.$approve.'" name="approvereq" />'.&mt('Approve').'</label></span><br />'.
  330:                            '<span class="LC_nobreak"><label>'.
  331:                            '<input type="checkbox" value="'.$reject.'" name="rejectreq" />'.&mt('Reject').'</label></span><br /></td>'.
  332:                            '<td>'.$namelink.'</td>'."\n";
  333:                     if ($context eq 'course') {
  334:                         $row .= '<td>'.$showsec.'</td>'."\n".
  335:                                 '<td>'.$showtime.'</td>'."\n";
  336:                     } else { 
  337:                         $row .= '<td>'.$crstype.'</td>'."\n".
  338:                                 '<td>'.$showtime.'</td>'."\n".
  339:                                 '<td>'.$detailslink.'</td>'."\n";
  340:                     }
  341:                     $output .= &Apache::loncommon::start_data_table_row()."\n".
  342:                                $row.
  343:                                &Apache::loncommon::end_data_table_row()."\n";
  344:                     $count ++;
  345:                 }
  346:             }
  347:         }
  348:         $output .= &Apache::loncommon::end_data_table().
  349:                    '<input type="submit" name="processqueue" value="'.&mt('Save').
  350:                    '" /></form>';
  351:     } else {
  352:         if ($context eq 'course') {
  353:             $output .= &mt('There are currently no enrollment requests.');
  354:         } else {
  355:             $output .= &mt('There are currently no course or community requests awaiting approval.');
  356:         }
  357:     }
  358:     return $output;
  359: }
  360: 
  361: sub update_request_queue {
  362:     my ($context,$cdom,$cnum,$coursedesc) = @_;
  363:     my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
  364:         $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
  365:         $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
  366:         @existing,@missingreq,@invalidusers,@limitexceeded,@completed,
  367:         @processing_errors,@warn_approves,@warn_rejects,@approvals,
  368:         @rejections,@rejectionerrors,@nopermissions,%courseroles,
  369:         %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,
  370:         @warn_coursereqs);
  371:     @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
  372:     @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
  373:     $now = time;
  374:     $sender = $env{'user.name'}.':'.$env{'user.domain'};
  375:     if ($context eq 'course') {
  376:         $namespace = 'selfenrollrequests';
  377:         $beneficiary = 'enroller';
  378:         $cid = $env{'request.course.id'};
  379:         $crstype = lc(&Apache::loncommon::course_type());
  380:         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
  381:         $hostname = &Apache::lonnet::hostname($chome);
  382:         $protocol = $Apache::lonnet::protocol{$chome};
  383:         $protocol = 'http' if ($protocol ne 'https');
  384:         %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
  385:         $access_start =  $env{'course.'.$cid.'.internal.selfenroll_start_access'};
  386:         $access_end =  $env{'course.'.$cid.'.internal.selfenroll_end_access'};
  387:         $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
  388:         $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
  389:         $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
  390:         ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
  391:         $approvedmsg = [{
  392:                             mt => 'Your request for enrollment has been approved.',
  393:                         },
  394:                         {
  395:                             mt   => 'Visit [_1], to log-in and access the course',
  396:                             args => [$protocol.'://'.$hostname],
  397:                         }];
  398:         $rejectedmsg =  [{
  399:                             mt => 'Your request for enrollment has not been approved.',
  400:                         }];
  401:     } else {
  402:         $domdesc = &Apache::lonnet::domain($cdom);
  403:         $namespace = 'courserequestqueue';
  404:         $beneficiary = 'courserequestor';
  405:         %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_approval');
  406:         my $chome = &Apache::lonnet::domain($cdom,'primary');
  407:         $hostname = &Apache::lonnet::hostname($chome);
  408:         $protocol = $Apache::lonnet::protocol{$chome};
  409:         $protocol = 'http' if ($protocol ne 'https');
  410:         my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
  411:         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
  412:             if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') { 
  413:                 $notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
  414:             }
  415:         }
  416:         $approvalmsg{'course'} = 
  417:                         [{
  418:                             mt => 'Your course request has been approved.',
  419:                         },
  420:                         {
  421:                             mt   => 'Visit [_1], to log-in and access the course',
  422:                             args => [$protocol.'://'.$hostname],
  423:                         }];
  424:         $rejectionmsg{'course'} =
  425:                         [{
  426:                             mt => 'Your course request has not been approved.',
  427:                         }];
  428: 
  429:         $approvalmsg{'community'} = 
  430:                         [{
  431:                             mt => 'Your community request has been approved.',
  432:                         },
  433:                         {
  434:                             mt   => 'Visit [_1], to log-in and access the community',
  435:                             args => [$protocol.'://'.$hostname],
  436:                         }];
  437: 
  438:         $rejectionmsg{'community'} = 
  439:                         [{
  440:                             mt => 'Your community request has not been approved.',
  441:                         }];
  442: 
  443:         %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
  444:         my @roles = &Apache::lonuserutils::roles_by_context('course');
  445:         foreach my $role (@roles) {
  446:             $courseroles{$role}=&Apache::lonnet::plaintext($role,'Course');
  447:         }
  448:         foreach my $role (@roles) {
  449:             $communityroles{$role}=&Apache::lonnet::plaintext($role,'Community');
  450:         }
  451: 
  452:     }
  453:     foreach my $item (sort {$a <=> $b} @approvals) {
  454:         if ($context eq 'course') {
  455:             my ($num,$uname,$udom,$usec) = split(/:/,$item);
  456:             my $uhome = &Apache::lonnet::homeserver($uname,$udom);
  457:             if ($uhome ne 'no_host') {
  458:                 if (exists($requesthash{$uname.':'.$udom})) {
  459: 
  460:                     if (exists($classlist->{$uname.':'.$udom})) {
  461:                         if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
  462:                             if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
  463:                                 ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
  464:                                 push(@existing,$uname.':'.$udom);
  465:                                 next;
  466:                             }
  467:                         }
  468:                     }
  469:                 } else {
  470:                     push(@missingreq,$uname.':'.$udom);
  471:                     next;
  472:                 }
  473:                 if (!grep(/^\Q$item\E$/,@rejections)) {
  474:                     if ($limit eq 'allstudents') {
  475:                         if ($stucounts->{$limit} >= $cap) {
  476:                             push(@limitexceeded,$uname.':'.$udom);
  477:                             last;
  478:                         }
  479:                     } elsif ($limit eq 'selfenrolled') {
  480:                         if ($stucounts->{$limit} >= $cap) {
  481:                             push(@limitexceeded,$uname.':'.$udom);
  482:                             last;
  483:                         }
  484:                     }
  485:                     my $result =
  486:                         &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
  487:                     if ($result eq 'ok') {
  488:                         push(@completed,$uname.':'.$udom);
  489:                         $stucounts->{'allstudents'} ++;
  490:                         $stucounts->{'selfenrolled'} ++;
  491:                         &send_selfserve_notification($uname.':'.$udom,$approvedmsg,
  492:                                        $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
  493:                         my %userrequest = (
  494:                             $cdom.'_'.$cnum => {
  495:                                 timestamp   => $now,
  496:                                 section     => $usec,
  497:                                 adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
  498:                                 status      => 'approved',
  499:                             }
  500:                         );
  501:                         my $userresult =
  502:                             &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
  503:                         if ($userresult ne 'ok') {
  504:                             push(@warn_approves,$uname.':'.$udom);
  505:                         } elsif ($udom eq 'gci') {
  506:                             my %changehash = (
  507:                                 'reqcrsotherdom.unofficial' => 'gcitest:autolimit=',
  508:                             );
  509:                             my $reqresult = &Apache::lonnet::put('environment',\%changehash,
  510:                                                                  $udom,$uname);
  511:                             if ($reqresult ne 'ok') {
  512:                                 push(@warn_coursereqs,$uname.':'.$udom);
  513:                             }
  514:                         }
  515:                     } else {
  516:                         push(@processing_errors,$uname.':'.$udom);
  517:                     }
  518:                 }
  519:             } else {
  520:                 push(@invalidusers,$uname.':'.$udom);
  521:             }
  522:         } else {
  523:             my ($num,$cnum) = split(':',$item);
  524:             if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
  525:                 if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  526:                     my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
  527:                     my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
  528:                     $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
  529:                     my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
  530:                     my $longroles = \%courseroles;
  531:                     if ($crstype eq 'community') {
  532:                         $longroles = \%communityroles;
  533:                     }
  534:                     my $cancreate;
  535:                     if ($cdom eq $ownerdom) {
  536:                         if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype,
  537:                                                               undef,'requestcourses')) {
  538:                             $cancreate = 1;
  539:                         }
  540:                     } else {
  541:                         my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype);
  542:                         if ($userenv{'reqcrsotherdom.'.$crstype}) {
  543:                             my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
  544:                             if (grep(/^\Q$cdom\E:/,@doms)) {
  545:                                 $cancreate = 1;
  546:                             }
  547:                         }
  548:                     }
  549:                     if ($cancreate) {
  550:                         my $requestkey = $cdom.'_'.$cnum;
  551:                         my %history = 
  552:                             &Apache::lonnet::restore($requestkey,'courserequests',
  553:                                                      $ownerdom,$ownername);
  554:                         if ((ref($history{'details'}) eq 'HASH') && 
  555:                             ($history{'disposition'} eq 'approval')) {
  556:                             my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
  557:                             my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
  558:                                                       \$newusermsg,\$addresult,\$enrollcount,
  559:                                                       \$response,\$keysmsg,\%domdefs,$longroles);
  560:                             if ($result eq 'created') {
  561:                                 if ($crstype eq 'community') {
  562:                                     $approvedmsg = $approvalmsg{'community'};
  563:                                 } else {
  564:                                     $approvedmsg = $approvalmsg{'course'};
  565:                                 }
  566:                                 push(@completed,$cnum);
  567:                                 &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
  568:                                               $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
  569:                                 my %reqhash = (
  570:                                                 reqtime     => $history{'reqtime'},
  571:                                                 crstype     => $history{'crstype'},
  572:                                                 details     => $history{'details'},
  573:                                                 disposition => $history{'disposition'},
  574:                                                 status      => 'created',
  575:                                                 adjudicator => $env{'user.name'}.':'.
  576:                                                                $env{'user.domain'},
  577:                                               );
  578:                                 my $userresult =
  579:                                     &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
  580:                                                    'courserequests',$ownerdom,$ownername);
  581:                                 if ($userresult eq 'ok') {
  582:                                     my %status = (
  583:                                                    'status:'.$cdom.':'.$cnum => 'created'
  584:                                                  );
  585:                                     my $statusresult = 
  586:                                         &Apache::lonnet::put('courserequests',\%status,
  587:                                                              $ownerdom,$ownername);
  588:                                     if ($statusresult ne 'ok') {
  589:                                         push(@warn_approves,$cnum);
  590:                                     }
  591:                                 }
  592:                                 if ($userresult ne 'ok') {
  593:                                     push(@warn_approves,$cnum);
  594:                                 }
  595:                             } else {
  596:                                 push(@processing_errors,$cnum);
  597:                             }
  598:                         } else {
  599:                             push(@processing_errors,$cnum);
  600:                         }
  601:                     } else {
  602:                         push(@nopermissions,$cnum);
  603:                     }
  604:                 } else {
  605:                     push(@existing,$cnum);
  606:                 }
  607:             } else {
  608:                 push(@missingreq,$cnum);
  609:             }
  610:         }
  611:     }
  612:     my @changes = (@completed,@rejections);
  613:     if ($context eq 'domain') {
  614:         @changes = map {$_.'_approval'} (@changes);
  615:     }
  616:     if (@rejections) {
  617:         foreach my $item (@rejections) {
  618:             if ($context eq 'course') {
  619:                 my $user = $item;
  620:                 &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
  621:                                              $now,$beneficiary,$sender,undef,undef,$crstype);
  622:                 my ($uname,$udom) = split(/:/,$user);
  623:                 my %userrequest = (
  624:                     $cdom.'_'.$cnum => {
  625:                         timestamp   => $now,
  626:                         adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
  627:                         status      => 'rejected',
  628:                     }
  629:                 );
  630:                 my $userresult =
  631:                     &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
  632:                 if ($userresult ne 'ok') {
  633:                     push(@warn_rejects,$user);
  634:                 }
  635:             } else {
  636:                 my $cnum = $item;
  637:                 if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
  638:                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
  639:                         my $requestkey = $cdom.'_'.$cnum;
  640:                         my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
  641:                         my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
  642:                         my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
  643:                         $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
  644:                         if ($crstype eq 'community') {
  645:                             $rejectedmsg = $rejectionmsg{'community'};
  646:                         } else {
  647:                             $rejectedmsg = $rejectionmsg{'course'};
  648:                         }
  649:                         &send_selfserve_notification($ownername.':'.$ownerdom,$rejectedmsg,
  650:                                                      $cid,$coursedesc,$now,$beneficiary,
  651:                                                      $sender,undef,undef,$crstype);
  652:                         my %history =
  653:                             &Apache::lonnet::restore($requestkey,'courserequests',
  654:                                                      $ownerdom,$ownername);
  655:                         if ((ref($history{'details'}) eq 'HASH') &&
  656:                             ($history{'disposition'} eq 'approval')) {
  657:                             my %reqhash = (
  658:                                             reqtime     => $history{'reqtime'},
  659:                                             crstype     => $history{'crstype'},
  660:                                             details     => $history{'details'},
  661:                                             disposition => $history{'disposition'},
  662:                                             status      => 'rejected',
  663:                                             adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
  664:                                               );
  665:                             my $userresult =
  666:                                 &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
  667:                                                 'courserequests',$ownerdom,$ownername);
  668:                             if ($userresult eq 'ok') {
  669:                                 my %status = (
  670:                                                'status:'.$cdom.':'.$cnum => 'rejected'
  671:                                              );
  672:                                 my $statusresult =
  673:                                     &Apache::lonnet::put('courserequests',\%status,
  674:                                                          $ownerdom,$ownername);
  675:                                 if ($statusresult ne 'ok') {
  676:                                     push(@warn_rejects,$cnum);
  677:                                 }
  678:                             } else {
  679:                                 push(@warn_rejects,$cnum);
  680:                             }
  681:                         } else {
  682:                             push(@warn_rejects,$cnum);
  683:                         }
  684:                     } else {
  685:                         push(@existing,$cnum);
  686:                     }
  687:                 } else {
  688:                     push(@rejectionerrors,$cnum);
  689:                 }
  690:             }
  691:         }
  692:     }
  693:     if (@changes) {
  694:         my $delresult;
  695:         if ($context eq 'course') {
  696:             $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
  697:         } else {
  698:             $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
  699:         }
  700:         if ($delresult eq 'ok') {
  701:             my $namelink =
  702:                 &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
  703:             my ($chgmsg,$approvedlist,$rejectedlist);
  704:             if ($context eq 'course') {
  705:                 $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
  706:                 if (@completed) {
  707:                     $approvedlist = join("\n",@completed);
  708:                     if ($crstype eq 'community') {
  709:                         $output .= '<p>'.&mt('The following were enrolled in the community:').'<ul>';
  710:                     } else {
  711:                         $output .= '<p>'.&mt('The following were enrolled in the course:').'<ul>';
  712:                     }
  713:                     foreach my $user (@completed) {
  714:                         my ($uname,$udom) = split(/:/,$user);
  715:                         my $userlink =
  716:                             &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
  717:                         $output .= '<li>'.$userlink.'</li>';
  718:                     }
  719:                     $output .= '</ul></p>';
  720:                 }
  721:                 if (@rejections) {
  722:                     $rejectedlist = join("\n",@rejections);
  723:                     $output .= '<p>'.&mt('The following enrollment requests were rejected:').'<ul>';
  724:                     foreach my $user (@rejections) {
  725:                         $output .= '<li>'.$user.'</li>';
  726:                     }
  727:                     $output .= '</ul></p>';
  728:                 }
  729:                 if ($notifylist ne '') {
  730:                     &send_selfserve_notification($notifylist,$chgmsg,$cid,$coursedesc,
  731:                                                  $now,'coursemanagers',$sender,
  732:                                                  $approvedlist,$rejectedlist,$crstype);
  733:                 }
  734:             } else {
  735:                 $chgmsg = "'Action was taken on the following course and community requests by [_1].',$namelink";
  736:                 if (@completed) {
  737:                     $approvedlist = join("\n",@completed);
  738:                     $output .= '<p>'.&mt('The following courses/communities were created:').'<ul>';
  739:                     foreach my $cnum (@completed) {
  740:                         my $showcourse;
  741:                         if (ref($requesthash{$cnum.'_approval'})) {
  742:                             $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  743:                         } else {
  744:                             $showcourse = $cnum;
  745:                         }
  746:                         my $syllabuslink =
  747:                             &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
  748:                         $output .= '<li>'.$syllabuslink.'</li>';
  749:                     }
  750:                     $output .= '</ul></p>';
  751:                 }
  752:                 if (@rejections) {
  753:                     $rejectedlist = join("\n",@rejections);
  754:                     $output .= '<p>'.&mt('The following requests were rejected:').'<ul>';
  755:                     foreach my $cnum (@rejections) {
  756:                         my $showcourse;
  757:                         if (ref($requesthash{$cnum.'_approval'})) {
  758:                             $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  759:                         } else {
  760:                             $showcourse = $cnum;
  761:                         }
  762:                         $output .= '<li>'.$showcourse.'</li>';
  763:                     }
  764:                     $output .= '</ul></p>';
  765:                 }
  766:                 if ($notifylist ne '') {
  767:                     &send_selfserve_notification($notifylist,$chgmsg,$cid,$domdesc,
  768:                                                  $now,'domainmanagers',$sender,
  769:                                                  $approvedlist,$rejectedlist,$crstype);
  770:                 }
  771:             }
  772:         }
  773:     }
  774:     if (@existing) {
  775:         if ($context eq 'course') {
  776:             $output .= '<p>'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'<ul>';
  777:             foreach my $user (@existing) {
  778:                 $output .= '<li>'.$user.'</li>';
  779:             }
  780:             $output .= '</ul></p>';
  781:         } else {
  782:             $output .= '<p>'.&mt('The following course/community creation requests were deleted because the course or community has already been created:').'<ul>';
  783:             foreach my $cnum (@existing) {
  784:                 my $showcourse;
  785:                 my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
  786:                 if ($coursehash{'description'} ne '') {
  787:                     $showcourse = $coursehash{'description'};
  788:                 } else {
  789:                     $showcourse = $cnum;
  790:                 }
  791:                 $output .= '<li>'.$showcourse.'</li>';
  792:             }
  793:             $output .= '</ul></p>';
  794:         }
  795:     }
  796:     if (@missingreq) {
  797:         if ($context eq 'course') {
  798:             $output .= '<p>'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'<ul>';
  799:             foreach my $user (@missingreq) {
  800:                 $output .= '<li>'.$user.'</li>';
  801:             }
  802:             $output .= '</ul></p>';
  803:         } else {
  804:             $output .= '<p>'.&mt('The following course/community creation requests were ignored because the request is no longer in the queue:').'<ul>';
  805:             foreach my $cnum (@missingreq) {
  806:                 $output .= '<li>'.$cnum.'</li>';
  807:             }
  808:             $output .= '</ul></p>';
  809: 
  810:         }
  811:     }
  812:     if (@invalidusers) {
  813:         if ($context eq 'course') {
  814:             $output .= '<p>'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
  815:             foreach my $user (@invalidusers) {
  816:                 $output .= '<li>'.$user.'</li>';
  817:             }
  818:             $output .= '</ul></p>';
  819:         }
  820:     }
  821:     if (@limitexceeded) {
  822:         if ($context eq 'course') {
  823:             $output .= '<p>'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'<ul>';
  824:             foreach my $user (@limitexceeded) {
  825:                 $output .= '<li>'.$user.'</li>';
  826:             }
  827:             $output .= '</ul></p>';
  828:         }
  829:     }
  830:     if (@nopermissions) {
  831:         $output .= '<p>'.&mt('The following course/community creation requests could not be processed because the owner does not have rights to create this type of course:').'<ul>';
  832:         foreach my $cnum (@nopermissions) {
  833:             my $showcourse;
  834:             if (ref($requesthash{$cnum.'_approval'})) {
  835:                 $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  836:             } else {
  837:                 $showcourse = $cnum;
  838:             }
  839:             $output .= '<li>'.$showcourse.'</li>';
  840:         }
  841:         $output .= '</ul></p>';
  842:     }
  843:     if (@processing_errors) {
  844:         if ($context eq 'course') {
  845:             $output .= '<p>'.&mt('The following enrollment requests could not be processed because an error occurred:').'<ul>';
  846:             foreach my $user (@processing_errors) {
  847:                 $output .= '<li>'.$user.'</li>';
  848:             }
  849:             $output .= '</ul></p>';
  850:         } else {
  851:             $output .= '<p>'.&mt('The following course/community creation requests could not be processed because an error occurred:').'<ul>';
  852:             foreach my $cnum (@processing_errors) {
  853:                 my $showcourse;
  854:                 if (ref($requesthash{$cnum.'_approval'})) {
  855:                     $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  856:                 } else {
  857:                     $showcourse = $cnum;
  858:                 }
  859:                 $output .= '<li>'.$showcourse.'</li>';
  860:             }
  861:             $output .= '</ul></p>';
  862:         }
  863:     }
  864:     if (@rejectionerrors) {
  865:         $output .= '<p>'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'<ul>';
  866:         foreach my $cnum (@rejectionerrors) {
  867:             my $showcourse;
  868:             if (ref($requesthash{$cnum.'_approval'})) {
  869:                 $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  870:             } else {
  871:                 $showcourse = $cnum;
  872:             }
  873:             $output .= '<li>'.$showcourse.'</li>';
  874:         }
  875:         $output .= '</ul></p>';
  876:     }
  877:     if (@warn_approves || @warn_rejects) {
  878:         if ($context eq 'course') {
  879:             $output .= '<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>';
  880:             foreach my $user (@warn_approves) {
  881:                 $output .= '<li>'.$user.'</li>';
  882:             }
  883:             $output .= '</ul></p>';
  884:         } else {
  885:             $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
  886:             foreach my $cnum (@warn_approves,@warn_rejects) {
  887:                 my $showcourse;
  888:                 if (ref($requesthash{$cnum.'_approval'})) {
  889:                     $showcourse = $requesthash{$cnum.'_approval'}{'description'};
  890:                 } else {
  891:                     $showcourse = $cnum;
  892:                 }
  893:                 $output .= '<li>'.$showcourse.'</li>';
  894:             }
  895:             $output .= '</ul></p>';
  896:         }
  897:     }
  898:     if (@warn_coursereqs) {
  899:         $output .= '<p>'..&mt("For the following users, an error occurred when setting rights to request creation of Concept Test courses:").'<ul>';
  900:             foreach my $user (@warn_coursereqs) {
  901:                 $output .= '<li>'.$user.'</li>';
  902:             }
  903:             $output .= '</ul></p>';
  904:     }
  905:     return $output;
  906: }
  907: 
  908: sub get_student_counts {
  909:     my ($cdom,$cnum) = @_;
  910:     my (%idx,%stucounts);
  911:     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
  912:     $idx{'type'} = &Apache::loncoursedata::CL_TYPE();
  913:     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
  914:     while (my ($student,$data) = each(%$classlist)) {
  915:         if (($data->[$idx{'status'}] eq 'Active') ||
  916:             ($data->[$idx{'status'}] eq 'Future')) {
  917:             if ($data->[$idx{'type'}] eq 'selfenroll') {
  918:                 $stucounts{'selfenroll'} ++;
  919:             }
  920:             $stucounts{'allstudents'} ++;
  921:         }
  922:     }
  923:     return (\%stucounts,\%idx,$classlist);
  924: }
  925: 
  926: sub course_creation {
  927:     my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
  928:         $keysmsg,$domdefs,$longroles) =  @_;
  929:     unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') && 
  930:             (ref($longroles) eq 'HASH')) {
  931:         return 'error: Invalid request';
  932:     }
  933:     my ($result,$ownername,$ownerdom);
  934:     my $crstype = $details->{'crstype'};
  935:     if ($context eq 'domain') {
  936:         $ownername = $details->{'owner'};
  937:         $ownerdom  = $details->{'domain'};
  938:     } else {
  939:         $ownername = $env{'user.name'};
  940:         $ownerdom  = $env{'user.domain'};
  941:     }
  942:     my $owneremail;
  943:     my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
  944:     foreach my $email ('permanentemail','critnotification','notification') {
  945:         $owneremail = $emails{$email};
  946:         last if ($owneremail ne '');
  947:     }
  948:     my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
  949:     my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
  950:                   \%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult,
  951:                   \$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype);
  952:     if ($cid eq "/$dom/$cnum") {
  953:         $result = 'created';
  954:     } else {
  955:         $result = 'error: '.$cid;
  956:     }
  957:     return $result;
  958: }
  959: 
  960: sub build_batchcreatehash {
  961:     my ($dom,$context,$details,$owneremail,$domdefs) = @_;
  962:     my %batchhash;
  963:     my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
  964:     if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
  965:         my $emailenc = &Apache::lonnet::escape($owneremail);
  966:         my $owner = $details->{'owner'}.':'.$details->{'domain'};
  967:         foreach my $item (@items) {
  968:             $batchhash{$item} = $details->{$item};
  969:         }
  970:         $batchhash{'title'} = $details->{'cdescr'};
  971:         $batchhash{'coursecode'} = $details->{'instcode'};
  972:         $batchhash{'emailenc'} = $emailenc;
  973:         $batchhash{'adds'} = $details->{'autoadds'};
  974:         $batchhash{'drops'} = $details->{'autodrops'};
  975:         $batchhash{'authtype'} = $domdefs->{'auth_def'};
  976:         $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
  977:         if ($details->{'crstype'} eq 'community') {
  978:             $batchhash{'crstype'} = 'Community';
  979:         } else {
  980:             $batchhash{'crstype'} = 'Course';
  981:         }
  982:         my ($owner_firstname,$owner_lastname);
  983:         if ($context eq 'domain') {
  984:             my %userenv = &Apache::lonnet::userenvironment($details->{'domain'},
  985:                                                            $details->{'owner'},
  986:                                                            'firstname','lastname');
  987:             $owner_firstname = $userenv{'firstname'};
  988:             $owner_lastname = $userenv{'lastname'};
  989:         } else {
  990:             $owner_firstname = $env{'environment.firstname'};
  991:             $owner_lastname = $env{'environment.lastname'};
  992:         }
  993:         if (ref($details->{'personnel'}) eq 'HASH') {
  994:             %{$batchhash{'users'}} = %{$details->{'personnel'}};
  995:             if (ref($batchhash{'users'}) eq 'HASH') {  
  996:                 foreach my $userkey (keys(%{$batchhash{'users'}})) {
  997:                     if (ref($batchhash{'users'}{$userkey}) eq 'HASH') {
  998:                         if (ref($batchhash{'users'}{$userkey}{'roles'}) eq 'ARRAY') {
  999:                             foreach my $role (@{$batchhash{'users'}{$userkey}{'roles'}}) {
 1000:                                 my $start = '';
 1001:                                 my $end = '';
 1002:                                 if ($role eq 'st') {
 1003:                                     $start = $details->{'accessstart'};
 1004:                                     $end = $details->{'accessend'};
 1005:                                 }
 1006:                                 $batchhash{'users'}{$userkey}{$role}{'start'} = $start;
 1007:                                 $batchhash{'users'}{$userkey}{$role}{'end'} = $end;
 1008:                             } 
 1009:                         }
 1010:                     }
 1011:                 }
 1012:             }
 1013:         }
 1014:         $batchhash{'users'}{$owner}{firstname} = $owner_firstname;
 1015:         $batchhash{'users'}{$owner}{lastname} = $owner_lastname;
 1016:         $batchhash{'users'}{$owner}{emailenc} = $emailenc;
 1017:         $batchhash{'users'}{$owner}{owneremail} = $owneremail;
 1018:     }
 1019:     return %batchhash;
 1020: }
 1021: 
 1022: sub can_clone_course {
 1023:     my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
 1024:     my $canclone;
 1025:     my $ccrole = 'cc';
 1026:     if ($crstype eq 'community') {
 1027:         $ccrole = 'co';
 1028:     }
 1029:     my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
 1030:                                                   [$ccrole],[$clonedom]);
 1031:     if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
 1032:         $canclone = 1;
 1033:     } else {
 1034:         my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
 1035:         my $cloners = $courseenv{'cloners'};
 1036:         if ($cloners ne '') {
 1037:             my @cloneable = split(',',$cloners);
 1038:             if (grep(/^\*$/,@cloneable)) {
 1039:                 $canclone = 1;
 1040:             }
 1041:             if (grep(/^\*:\Q$udom\E$/,@cloneable)) {
 1042:                 $canclone = 1;
 1043:             }
 1044:             if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) {
 1045:                 $canclone = 1;
 1046:             }
 1047:         }
 1048:     }
 1049:     return $canclone;
 1050: }
 1051: 
 1052: 1;

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