Annotation of loncom/interface/lonrequestcourse.pm, revision 1.41.2.9

1.1       raeburn     1: # The LearningOnline Network
                      2: # Request a course
                      3: #
1.41.2.9! raeburn     4: # $Id: lonrequestcourse.pm,v 1.41.2.8 2010/11/08 21:44:55 raeburn Exp $
1.1       raeburn     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::lonrequestcourse.pm
                     33: 
                     34: =head1 SYNOPSIS
                     35: 
                     36: Allows users to request creation of new courses.
                     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 handler()
                     46: 
1.27      raeburn    47: =item get_breadcrumbs()
                     48: 
1.12      raeburn    49: =item header()
                     50: 
                     51: =item form_elements()
                     52: 
                     53: =item onload_action()
                     54: 
                     55: =item print_main_menu()
                     56: 
                     57: =item request_administration()
                     58: 
1.27      raeburn    59: =item close_popup_form()
                     60: 
                     61: =item get_instcode()
                     62: 
1.12      raeburn    63: =item print_request_form()
                     64: 
                     65: =item print_enrollment_menu()
                     66: 
1.27      raeburn    67: =item show_invalid_crosslists()
                     68: 
1.12      raeburn    69: =item inst_section_selector()
                     70: 
                     71: =item date_setting_table()
                     72: 
                     73: =item print_personnel_menu()
                     74: 
                     75: =item print_request_status()
                     76: 
                     77: =item print_request_logs()
                     78: 
                     79: =item print_review()
                     80: 
                     81: =item dates_from_form()
                     82: 
                     83: =item courseinfo_form()
                     84: 
                     85: =item clone_form()
                     86: 
                     87: =item clone_text()
                     88: 
                     89: =item coursecode_form()
                     90: 
                     91: =item get_course_dom()
                     92: 
                     93: =item display_navbuttons()
                     94: 
                     95: =item print_request_outcome()
                     96: 
                     97: =item get_processtype()
                     98: 
                     99: =item check_autolimit()
                    100: 
                    101: =item retrieve_settings()
                    102: 
                    103: =item get_request_settings()
                    104: 
1.27      raeburn   105: =item extract_instcode() 
                    106: 
                    107: =item generate_date_items()
                    108: 
1.1       raeburn   109: =back
                    110: 
                    111: =cut
                    112: 
                    113: package Apache::lonrequestcourse;
                    114: 
                    115: use strict;
                    116: use Apache::Constants qw(:common :http);
                    117: use Apache::lonnet;
                    118: use Apache::loncommon;
                    119: use Apache::lonlocal;
1.8       raeburn   120: use Apache::loncoursequeueadmin;
1.30      raeburn   121: use Apache::lonuserutils;
1.4       raeburn   122: use LONCAPA qw(:DEFAULT :match);
1.1       raeburn   123: 
                    124: sub handler {
                    125:     my ($r) = @_;
1.20      raeburn   126:     &Apache::loncommon::content_type($r,'text/html');
                    127:     $r->send_http_header;
1.1       raeburn   128:     if ($r->header_only) {
                    129:         return OK;
                    130:     }
1.27      raeburn   131:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.38      raeburn   132:         ['action','showdom','cnum','state','crstype']);
1.2       raeburn   133:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.41.2.8  raeburn   134:     my $action = $env{'form.reqaction'};
1.1       raeburn   135:     my $state = $env{'form.state'};
1.41.2.8  raeburn   136:     my $context;
                    137:     &generate_page($r,$action,$state,$context);
                    138:     return OK;
                    139: }
                    140: 
                    141: sub generate_page {
                    142:     my ($r,$action,$state,$context) = @_;
                    143:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    144:         ['action','showdom','cnum','state','crstype']);
                    145:     my $dom = &get_course_dom();
1.27      raeburn   146:     my (%states,%stored);
                    147:     my ($jscript,$uname,$udom,$result,$warning);
                    148: 
                    149:     $states{'display'} = ['details'];
                    150:     $states{'view'} = ['pick_request','details','cancel','removal'];
                    151:     $states{'log'} = ['filter','display'];
                    152:     $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
                    153: 
1.41.2.1  raeburn   154:     if ($dom eq 'gcitest') {
                    155:         $states{'new'} = ['courseinfo','review','process'];
1.41.2.8  raeburn   156:         if ($env{'form.concepttest'} eq 'editmyown') {
                    157:             push(@{$states{'new'}},'chooseitems','uploadroster','enrolling');
                    158:         } elsif (($env{'form.concepttest'} eq 'defchosen') || 
                    159:                  (($env{'form.concepttest'} eq 'cloning') && (!$env{'form.cloneroster'}))) {
                    160:             push(@{$states{'new'}},'uploadroster','enrolling');
                    161:         } else {
                    162:             push(@{$states{'new'}},'done');
                    163:         }
1.41.2.1  raeburn   164:     }
1.27      raeburn   165:     if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
1.41.2.8  raeburn   166:         unless ($state eq 'crstype') {
1.27      raeburn   167:             unshift(@{$states{'new'}},'codepick');
                    168:         }
                    169:     }
                    170: 
                    171:     foreach my $key (keys(%states)) {
                    172:         if (ref($states{$key}) eq 'ARRAY') {
                    173:             unshift (@{$states{$key}},'crstype');
                    174:         }
                    175:     }
                    176: 
                    177:     my @invalidcrosslist;
                    178:     my %trail = (
1.40      raeburn   179:                  crstype       => 'Request Action',
1.27      raeburn   180:                  codepick      => 'Category',
                    181:                  courseinfo    => 'Description',
                    182:                  enrollment    => 'Access Dates',
                    183:                  personnel     => 'Personnel',
                    184:                  review        => 'Review',
                    185:                  process       => 'Result',
                    186:                  pick_request  => 'Display Summary',
                    187:                  details       => 'Request Details',
                    188:                  cancel        => 'Cancel Request',
                    189:                  removal       => 'Outcome',
1.41.2.8  raeburn   190:                  chooseitems   => 'Saved Test',
                    191:                  uploadroster  => 'Upload Roster',
                    192:                  enrolling     => 'Completed',
                    193:                  done          => 'Completed',
1.27      raeburn   194:                 );
1.41.2.1  raeburn   195:     if ($dom eq 'gcitest') {
                    196:         $trail{'crstype'} = 'Building a Test';
                    197:         $trail{'courseinfo'} = 'Test Information';
                    198:     }
1.27      raeburn   199: 
                    200:     if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
                    201:         $trail{'enrollment'} = 'Enrollment';
                    202:     }
                    203: 
1.36      raeburn   204:     my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = 
1.27      raeburn   205:         &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26      raeburn   206:     if ($action eq 'display') {
                    207:         if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
                    208:             my $namespace = 'courserequestqueue';
                    209:             if ($env{'form.cnum'} ne '') {
                    210:                 my $cnum = $env{'form.cnum'};
                    211:                 my $reqkey = $cnum.'_approval';
                    212:                 my $namespace = 'courserequestqueue';
                    213:                 my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
                    214:                 my %queued =
                    215:                     &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
                    216:                 if (ref($queued{$reqkey}) eq 'HASH') {
                    217:                     $uname = $queued{$reqkey}{'ownername'};
                    218:                     $udom  = $queued{$reqkey}{'ownerdom'};
                    219:                     if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
                    220:                         $result = &retrieve_settings($dom,$cnum,$udom,$uname);
                    221:                     } else {
1.40      raeburn   222:                         if ($env{'form.crstype'} eq 'community') {
                    223:                             $warning = &mt('Invalid username or domain for community requestor');
                    224:                         } else {
                    225:                             $warning = &mt('Invalid username or domain for course requestor');
                    226:                         }
1.26      raeburn   227:                     }
                    228:                 } else {
1.40      raeburn   229:                     if ($env{'form.crstype'} eq 'community') {
                    230:                         $warning = &mt('No information was found for this community request.');
                    231:                     } else {
                    232:                         $warning = &mt('No information was found for this course request.');
                    233:                     }
1.26      raeburn   234:                 }
                    235:             } else {
                    236:                 $warning = &mt('No course request ID provided.');
                    237:             }
                    238:         } else {
1.40      raeburn   239:             if ($env{'form.crstype'} eq 'any') {
                    240:                $warning = &mt('You do not have rights to view course or community request information.');
                    241:             } elsif ($env{'form.crstype'} eq 'community') {
                    242:                 $warning = &mt('You do not have rights to view community request information.');
                    243:             } else {
                    244:                 $warning = &mt('You do not have rights to view course request information.');
                    245:             }
1.26      raeburn   246:         }
                    247:     } elsif ((defined($state)) && (defined($action))) {
1.16      raeburn   248:         if (($action eq 'view') && ($state eq 'details')) {
                    249:             if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
                    250:                 my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2       raeburn   251:             }
1.27      raeburn   252:         } elsif ($env{'form.crstype'} eq 'official') {
                    253:             if (&Apache::lonnet::auto_run('',$dom)) {
                    254:                 if (($action eq 'new') && (($state eq 'enrollment') || 
                    255:                     ($state eq 'personnel'))) {
                    256:                     my $checkcrosslist = 0;
                    257:                     for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    258:                         if ($env{'form.crosslist_'.$i}) {
                    259:                             $checkcrosslist ++;
                    260:                         }
                    261:                     }
                    262:                     if ($checkcrosslist) {
                    263:                         my %codechk;
                    264:                         my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
                    265:                         &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
                    266:                                                                  \%cat_titles,
                    267:                                                                  \%cat_order,
                    268:                                                                  \@code_order);
                    269:                         my $numtitles = scalar(@codetitles);
                    270:                         if ($numtitles) {
                    271:                             for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    272:                                 if ($env{'form.crosslist_'.$i}) {
                    273:                                     my $codecheck;
                    274:                                     my $crosslistcode = '';
                    275:                                     foreach my $item (@code_order) {
                    276:                                         $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item}; 
                    277:                                     }
                    278:                                     if ($crosslistcode ne '') { 
1.36      raeburn   279:                                          ($codechk{$i}, my $rest) = 
1.27      raeburn   280:                                             &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
                    281:                                     }
                    282:                                     unless ($codechk{$i} eq 'valid') {
                    283:                                         $env{'form.crosslist_'.$i} = '';
                    284:                                         push(@invalidcrosslist,$crosslistcode);
                    285:                                     } 
                    286:                                 }
                    287:                             }
                    288:                         }
                    289:                     }
                    290:                 }
                    291:             }
1.2       raeburn   292:         }
1.16      raeburn   293:         my %elements =  &form_elements($dom);
1.2       raeburn   294:         my $elementsref = {};
                    295:         if (ref($elements{$action}) eq 'HASH') {
                    296:             if (ref($elements{$action}{$state}) eq 'HASH') {
                    297:                 $elementsref = $elements{$action}{$state};
                    298:             }
                    299:         }
1.16      raeburn   300:         if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
                    301:             $env{'form.clonedom'} = $dom;
                    302:         }
1.30      raeburn   303:         if ($state eq 'crstype') {
1.41.2.8  raeburn   304:             $jscript = &mainmenu_javascript($action);
1.30      raeburn   305:         } else {
                    306:             $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.41.2.6  raeburn   307:             if ($state eq 'courseinfo') {
                    308:                 $jscript .= &cloning_javascript();
                    309:             }
1.30      raeburn   310:         }
1.2       raeburn   311:     }
                    312: 
                    313:     if ($state eq 'personnel') {
                    314:         $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
                    315:     }
                    316: 
1.41.2.6  raeburn   317:     my $loaditems = &onload_action($action,$state,$dom);
1.2       raeburn   318: 
1.39      raeburn   319:     my (%can_request,%request_domains);
                    320:     my $canreq = 
                    321:         &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
1.1       raeburn   322:     if ($action eq 'new') {
                    323:         if ($canreq) {
                    324:             if ($state eq 'crstype') {
1.3       raeburn   325:                 &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.39      raeburn   326:                                  $crumb,\%request_domains);
1.1       raeburn   327:             } else {
1.27      raeburn   328:                 &request_administration($r,$action,$state,$page,\%states,$dom,
                    329:                                         $jscript,$loaditems,$crumb,$newinstcode,
1.36      raeburn   330:                                         $codechk,$checkedcode,$description,
                    331:                                         \@invalidcrosslist);
1.41.2.8  raeburn   332:                 if ($state eq 'chooseitems' || $state eq 'uploadroster' || 
                    333:                     $state eq 'enrolling') {
                    334:                     return $canreq;
                    335:                 }
1.1       raeburn   336:             }
                    337:         } else {
1.40      raeburn   338:             $r->print(&header('Course/Community Requests').$crumb.
1.1       raeburn   339:                       '<div class="LC_warning">'.
1.40      raeburn   340:                       &mt('You do not have privileges to request creation of courses or communities.').
1.2       raeburn   341:                       '</div>'.&Apache::loncommon::end_page());
1.1       raeburn   342:         }
                    343:     } elsif ($action eq 'view') {
1.10      raeburn   344:         if ($state eq 'crstype') {
1.39      raeburn   345:             &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
1.26      raeburn   346:         } else {
                    347:             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
                    348:                                     $loaditems,$crumb);
                    349:         }
                    350:     } elsif ($action eq 'display') {
                    351:         if ($warning ne '') {
                    352:             my $args = { only_body => 1 };
1.40      raeburn   353:             $r->print(&header('Course/Community Requests','','',$args).$crumb.
                    354:                       '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26      raeburn   355:                       '<div class="LC_warning">'.$warning.'</div>'.
                    356:                       &close_popup_form());
1.11      raeburn   357:         } else {
1.26      raeburn   358:             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.36      raeburn   359:                                     $loaditems,$crumb,'','','','','',$uname,$udom);
1.10      raeburn   360:         }
1.1       raeburn   361:     } elsif ($action eq 'log') {
1.3       raeburn   362:         &print_request_logs($jscript,$loaditems,$crumb);
1.1       raeburn   363:     } else {
1.39      raeburn   364:         &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
1.1       raeburn   365:     }
1.41.2.8  raeburn   366:     return;
1.1       raeburn   367: }
                    368: 
1.30      raeburn   369: sub mainmenu_javascript {
1.41.2.8  raeburn   370:     my ($action) = @_;
1.30      raeburn   371:     return <<"END";
                    372: function setType(courseForm) {
                    373:     for (var i=0; i<courseForm.crstype.length; i++) {
                    374:         if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
                    375:             courseForm.crstype.options[i].selected = true;
                    376:         } else {
                    377:             courseForm.crstype.options[i].selected = false;
                    378:         }
                    379:     }
                    380: }
                    381: 
                    382: function setAction(courseForm) {
1.41.2.8  raeburn   383:     for (var i=0; i<courseForm.reqaction.length; i++) {
                    384:         if (courseForm.reqaction.options[i].value == "$action") {
                    385:             courseForm.reqaction.options[i].selected = true;
1.30      raeburn   386:         } else {
1.41.2.8  raeburn   387:             courseForm.reqaction.options[i].selected = false;
1.30      raeburn   388:         }
                    389:     }
                    390: }
                    391: END
                    392: }
                    393: 
1.41.2.6  raeburn   394: sub cloning_javascript {
                    395:     return <<"END";
                    396: function setCloneDisplay(courseForm) {
                    397:     if (courseForm.cloning.length > 1) {
                    398:         for (var i=0; i<courseForm.cloning.length; i++) {
                    399:             if (courseForm.cloning[i].checked) {
                    400:                 if (courseForm.cloning[i].value == 1) {
                    401:                     document.getElementById('cloneoptions').style.display="block";;
                    402:                 }
                    403:             }
                    404:         }
                    405:     }
                    406: }
                    407: END
                    408: }
                    409: 
1.27      raeburn   410: sub get_breadcrumbs {
                    411:     my ($dom,$action,$state,$states,$trail) = @_;
1.36      raeburn   412:     my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27      raeburn   413:     my $page = 0;
1.41.2.1  raeburn   414:     my $firstcrumb = 'Pick Action';
                    415:     my $crumbtitle = 'Course/Community Requests';
                    416:     my $crumbhelp = 'Course_Requests';
                    417:     if ($dom eq 'gcitest') {
                    418:         $firstcrumb = 'Building a Test';
                    419:         $crumbtitle = 'Create Concept Test';
                    420:         $crumbhelp = 'Concept_Test_Creation';
                    421:     }
1.27      raeburn   422:     if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
                    423:         if (defined($action)) {
                    424:             my $done = 0;
                    425:             my $i=0;
                    426:             if (ref($states->{$action}) eq 'ARRAY') {
                    427:                 while ($i<@{$states->{$action}} && !$done) {
                    428:                     if ($states->{$action}[$i] eq $$state) {
                    429:                         $page = $i;
                    430:                         $done = 1;
                    431:                     }
                    432:                     $i++;
                    433:                 }
                    434:             }
                    435:             if ($env{'form.crstype'} eq 'official') {
                    436:                 if ($page > 1) {
                    437:                     if ($states->{$action}[$page-1] eq 'codepick') {
                    438:                         if ($env{'form.instcode'} eq '') {
                    439:                             ($newinstcode,$numtitles) = &get_instcode($dom);
                    440:                             if ($numtitles) {
                    441:                                 if ($newinstcode eq '') {
                    442:                                     $$state = 'codepick';
                    443:                                     $page --;
                    444:                                 } else {
1.36      raeburn   445:                                     ($codechk,$description) = 
1.27      raeburn   446:                                         &Apache::lonnet::auto_validate_instcode('',
                    447:                                             $dom,$newinstcode);
                    448:                                     if ($codechk ne 'valid') {
                    449:                                         $$state = 'codepick';
                    450:                                         $page --;
                    451:                                     }
                    452:                                     $checkedcode = 1;
                    453:                                 }
                    454:                             }
                    455:                         }
                    456:                     }
                    457:                 }
                    458:             }
1.41.2.8  raeburn   459:             my %forms = (
                    460:                           chooseitems  => 'requestcrs',
                    461:                           uploadroster => 'studentform',
                    462:                           enrolling    => 'requestcrs',
                    463:                           done         => 'requestcrs',
                    464:                         );
                    465:             my $lastidx;
                    466:             for (my $i=0; $i<@{$states->{$action}}; $i++) {
                    467:                 if ($$state eq $states->{$action}[$i]) {
                    468:                     $lastidx = $i;
                    469:                     last;
                    470:                 }
                    471:             }
1.27      raeburn   472:             for (my $i=0; $i<@{$states->{$action}}; $i++) {
                    473:                 if ($$state eq $states->{$action}[$i]) {
                    474:                     &Apache::lonhtmlcommon::add_breadcrumb(
                    475:                        {text=>"$trail->{$$state}"});
1.41.2.1  raeburn   476:                     $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27      raeburn   477:                     last;
                    478:                 } else {
                    479:                     if (($$state eq 'process') || ($$state eq 'removal')) {
                    480:                         &Apache::lonhtmlcommon::add_breadcrumb(
                    481:                             { href => '/adm/requestcourse',
                    482:                               text => "$trail->{$states->{$action}[$i]}",
                    483:                             }
                    484:                         );
                    485:                     } else {
1.41.2.8  raeburn   486:                         if (($$state eq 'chooseitems') || ($$state eq 'uploadroster') ||
                    487:                             ($$state eq 'enrolling') || ($$state eq 'done')) {
                    488:                             if (($states->{$action}[$i] ne 'process') &&
                    489:                                 ($states->{$action}[$i] ne 'chooseitems') &&
                    490:                                 ($states->{$action}[$i] ne 'uploadroster') &&
                    491:                                 ($states->{$action}[$i] ne 'enrolling') &&
                    492:                                 ($states->{$action}[$i] ne 'done')) {
                    493:                                 &Apache::lonhtmlcommon::add_breadcrumb(
                    494:                                    { href => '/adm/requestcourse',
                    495:                                      text => "$trail->{$states->{$action}[$i]}",
                    496:                                    }
                    497:                                 );
                    498:                             } else {
                    499:                                 my $diff = $i-$lastidx;
                    500:                                 &Apache::lonhtmlcommon::add_breadcrumb(
                    501:      { href => "javascript:history.go($diff)",
                    502:        text => "$trail->{$states->{$action}[$i]}", }
                    503:                                );
                    504:                             }
                    505:                         } else {
                    506:                             &Apache::lonhtmlcommon::add_breadcrumb(
1.27      raeburn   507:      { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
                    508:        text => "$trail->{$states->{$action}[$i]}", }
1.41.2.8  raeburn   509:                            );
                    510:                         }
                    511:                     }
                    512:                 }
                    513:             }
1.27      raeburn   514:         } else {
                    515:             &Apache::lonhtmlcommon::add_breadcrumb(
1.41.2.1  raeburn   516:                     {text=>$firstcrumb});
                    517:             $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27      raeburn   518:         }
                    519:     } else {
                    520:         &Apache::lonhtmlcommon::add_breadcrumb(
1.41.2.1  raeburn   521:                 {text=>$firstcrumb});
                    522:         $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27      raeburn   523:     }
1.36      raeburn   524:     return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27      raeburn   525: }
                    526: 
1.2       raeburn   527: sub header {
1.26      raeburn   528:     my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2       raeburn   529:     if ($jscript) {
1.6       raeburn   530:         $jscript = '<script type="text/javascript">'."\n".
                    531:                    '// <![CDATA['."\n".
                    532:                    $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2       raeburn   533:     }
                    534:     if ($loaditems) {
1.26      raeburn   535:         if (ref($args) eq 'HASH') {
                    536:             my %loadhash = (
                    537:                              'add_entries' => $loaditems,
1.41.2.8  raeburn   538:                              'function'    => 'norole',
1.26      raeburn   539:                            );
                    540:             my %arghash = (%loadhash,%{$args});
1.41.2.8  raeburn   541:             $args = \%arghash;
1.26      raeburn   542:         } else {
1.41.2.8  raeburn   543:             $args = {'add_entries' => $loaditems,
                    544:                      'function'    => 'norole'};
1.26      raeburn   545:         }
1.3       raeburn   546:     }
1.26      raeburn   547:     return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2       raeburn   548: }
                    549: 
                    550: sub form_elements {
                    551:     my ($dom) = @_;
                    552:     my %elements =
                    553:     (
                    554:         new => {
                    555:             crstype => {
                    556:                 crstype => 'selectbox',
                    557:                 action  => 'selectbox',
1.16      raeburn   558:                 origcnum => 'hidden', 
1.2       raeburn   559:             },
                    560:             courseinfo => {
                    561:                 cdescr           => 'text',
1.41.2.6  raeburn   562:                 cloning          => 'radio',
1.13      raeburn   563:                 clonecrs         => 'text',
                    564:                 clonedom         => 'selectbox',
1.2       raeburn   565:                 datemode         => 'radio',
                    566:                 dateshift        => 'text',
                    567:             },
                    568:             enrollment  => {
1.13      raeburn   569:                 accessstart_month  => 'selectbox',
                    570:                 accessstart_hour   => 'selectbox',
                    571:                 accessend_month    => 'selectbox',
                    572:                 accessend_hour     => 'selectbox',
                    573:                 accessstart_day    => 'text',
                    574:                 accessstart_year   => 'text',
                    575:                 accessstart_minute => 'text',
                    576:                 accessstart_second => 'text',
                    577:                 accessend_day      => 'text',
                    578:                 accessend_year     => 'text',
                    579:                 accessend_minute   => 'text',
                    580:                 accessend_second   => 'text',
1.2       raeburn   581:                 no_end_date      => 'checkbox',
                    582:             },
                    583:             personnel => {
                    584:                 addperson   => 'checkbox', 
                    585:             },
1.13      raeburn   586:             review => {
                    587:                 cnum => 'hidden',
                    588:             },
1.2       raeburn   589:          },
                    590:          view => {
                    591:             crstype => {
                    592:                 crstype => 'selectbox',
                    593:                 action  => 'selectbox',
                    594:             },
                    595:          },
                    596:     );
1.13      raeburn   597:     my %servers = &Apache::lonnet::get_servers($dom,'library');
1.41.2.1  raeburn   598:     if ($dom eq 'gcitest') {
                    599:         %{$elements{'new'}{'courseinfo'}} = (
                    600:                                               cdescr      => 'text',
1.41.2.6  raeburn   601:                                               concepttest => 'radio',
1.41.2.1  raeburn   602:                                             );
1.41.2.9! raeburn   603:         $elements{'new'}{'enrollment'}{'timezone'} = 'selectbox';
1.41.2.6  raeburn   604:         if (&show_cloneable()) {
                    605:             $elements{'new'}{'courseinfo'}{'clonecrs'} = 'selectbox';
                    606:             $elements{'new'}{'courseinfo'}{'clonedom'} = 'hidden';
                    607:             $elements{'new'}{'courseinfo'}{'cloneroster'} = 'checkbox';
                    608:         }
1.41.2.1  raeburn   609:     }
1.13      raeburn   610:     my $numlib = keys(%servers);
                    611:     if ($numlib > 1) {
                    612:         $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
                    613:     } else {
                    614:         $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
                    615:     }
1.41.2.1  raeburn   616:     if ($dom eq 'gcitest') {
                    617:         my %mergedhash = (%{$elements{'new'}{'courseinfo'}},%{$elements{'new'}{'enrollment'}});
                    618:         %{$elements{'new'}{'courseinfo'}} = %mergedhash;
                    619:     }
1.2       raeburn   620:     my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
                    621:     &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                    622:                                              \%cat_order,\@code_order);
                    623:     my $numtitles = scalar(@codetitles);
                    624:     if ($numtitles) {
                    625:         my %extras;
                    626:         $lastitem = pop(@codetitles);
                    627:         $extras{'instcode_'.$lastitem} = 'text'; 
                    628:         foreach my $item (@codetitles) {
                    629:             $extras{'instcode_'.$item} = 'selectbox';   
                    630:         }
                    631:         $elements{'new'}{'codepick'} = \%extras;
                    632:     }
                    633:     if (&Apache::lonnet::auto_run('',$dom)) {
                    634:         my %extras = (
                    635:                        sectotal           => 'hidden',
1.13      raeburn   636:                        enrollstart_month  => 'selectbox',
                    637:                        enrollstart_hour   => 'selectbox',
                    638:                        enrollend_month    => 'selectbox',
                    639:                        enrollend_hour     => 'selectbox',
                    640:                        enrollstart_day    => 'text',
                    641:                        enrollstart_year   => 'text',
                    642:                        enrollstart_minute => 'text',
                    643:                        enrollstart_second => 'text',
                    644:                        enrollend_day      => 'text',
                    645:                        enrollend_year     => 'text',
                    646:                        enrollend_minute   => 'text',
                    647:                        enrollend_second   => 'text',
1.2       raeburn   648:                        addcrosslist       => 'checkbox',
                    649:                        autoadds           => 'radio',
                    650:                        autodrops          => 'radio',
                    651:                      );
                    652:         if ($env{'form.sectotal'} > 0) {
                    653:             for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31      raeburn   654:                 $extras{'sec_'.$i} = 'radio';
                    655:                 $extras{'secnum_'.$i} = 'text';
                    656:                 $extras{'loncapasec_'.$i} = 'text';
1.2       raeburn   657:             }
                    658:         }
                    659:         my $crosslisttotal = $env{'form.crosslisttotal'};
1.16      raeburn   660:         if ($env{'form.addcrosslist'}) {
                    661:             $crosslisttotal ++;
                    662:         }
1.24      raeburn   663:         if (!$crosslisttotal) {
1.2       raeburn   664:             $crosslisttotal = 1;
                    665:         }
1.27      raeburn   666: 
1.24      raeburn   667:         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    668:             if ($numtitles) {
                    669:                 $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
                    670:             }
                    671:             if (@codetitles > 0) {
                    672:                 foreach my $item (@codetitles) {
                    673:                     $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2       raeburn   674:                 }
                    675:             }
1.24      raeburn   676:             $extras{'crosslist_'.$i} = 'checkbox';
                    677:             $extras{'crosslist_'.$i.'_instsec'} = 'text',
                    678:             $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2       raeburn   679:         }
                    680:         my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
                    681:         %{$elements{'new'}{'enrollment'}} = %mergedhash;
                    682:     }
                    683:     my %people;
                    684:     my $persontotal = $env{'form.persontotal'};
1.16      raeburn   685:     if ($env{'form.addperson'}) {
                    686:         $persontotal ++;
                    687:     }
                    688:     if ((!defined($persontotal)) || (!$persontotal)) {
1.2       raeburn   689:         $persontotal = 1;
                    690:     }
                    691:     for (my $i=0; $i<$persontotal; $i++) {
1.13      raeburn   692:         $people{'person_'.$i.'_uname'}     = 'text',
                    693:         $people{'person_'.$i.'_dom'}       = 'selectbox',
                    694:         $people{'person_'.$i.'_hidedom'}   = 'hidden',
                    695:         $people{'person_'.$i.'_firstname'} = 'text',
                    696:         $people{'person_'.$i.'_lastname'}  = 'text',
                    697:         $people{'person_'.$i.'_emailaddr'} = 'text',
                    698:         $people{'person_'.$i.'_role'}      = 'selectbox',
                    699:         $people{'person_'.$i.'_sec'}       = 'selectbox',
                    700:         $people{'person_'.$i.'_newsec'}    = 'text',
1.2       raeburn   701:     }
                    702:     my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
                    703:     %{$elements{'new'}{'personnel'}} = %personnelhash;
                    704:     return %elements;
                    705: }
                    706: 
                    707: sub onload_action {
                    708:     my ($action,$state) = @_;
                    709:     my %loaditems;
                    710:     if (($action eq 'new') || ($action eq 'view')) {
1.30      raeburn   711:         if ($state eq 'crstype') {
                    712:             $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
                    713:         } else {
1.41.2.6  raeburn   714:             $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
                    715:         }
1.2       raeburn   716:     }
                    717:     return \%loaditems;
                    718: }
                    719: 
1.1       raeburn   720: sub print_main_menu {
1.39      raeburn   721:     my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
1.37      raeburn   722:     my ($types,$typename) = &Apache::loncommon::course_types();
1.1       raeburn   723:     my $onchange;
                    724:     unless ($env{'form.interface'} eq 'textual') {
1.39      raeburn   725:         $onchange = 'this.form.submit()';
1.1       raeburn   726:     }
                    727: 
1.2       raeburn   728:     my $nextstate_setter = "\n";
                    729:     if (ref($states) eq 'HASH') {
                    730:         foreach my $key (keys(%{$states})) {
                    731:             if (ref($states->{$key}) eq 'ARRAY') {
                    732:                 $nextstate_setter .= 
                    733: "             if (actionchoice == '$key') {
                    734:                   nextstate = '".$states->{$key}[1]."';
                    735:              }
                    736: ";
                    737:             }
                    738:         }
                    739:     }
1.1       raeburn   740: 
1.41.2.1  raeburn   741:     my $js;
                    742:     unless ($dom eq 'gcitest') {
                    743:         $js = <<"END";
1.1       raeburn   744: 
1.2       raeburn   745: function nextPage(formname) {
1.27      raeburn   746:     var crschoice = document.mainmenu_coursetype.crstype.value;
1.41.2.8  raeburn   747:     var actionchoice = document.mainmenu_action.reqaction.value;
1.2       raeburn   748:     if (check_can_request(crschoice,actionchoice) == true) {
                    749:         if ((actionchoice == 'new') && (crschoice == 'official')) {
                    750:             nextstate = 'codepick';
                    751:         } else {
                    752: $nextstate_setter 
1.27      raeburn   753:         }
                    754:         formname.crstype.value = crschoice;
1.41.2.8  raeburn   755:         formname.reqaction.value = actionchoice; 
1.1       raeburn   756:         formname.state.value= nextstate;
                    757:         formname.submit();
                    758:     }
                    759:     return;
                    760: }
                    761: 
1.2       raeburn   762: function check_can_request(crschoice,actionchoice) {
1.1       raeburn   763:     var official = '';
                    764:     var unofficial = '';
                    765:     var community = '';    
                    766: END
1.41.2.1  raeburn   767:         if (ref($can_request) eq 'HASH') {
                    768:             foreach my $item (keys(%{$can_request})) {
                    769:                     $js .= " 
                    770:             $item = 1;
1.1       raeburn   771: ";
1.41.2.1  raeburn   772:             }
1.39      raeburn   773:         }
1.41.2.1  raeburn   774:         my %lt = &Apache::lonlocal::texthash(
                    775:             official => 'You are not permitted to request creation of an official course in this domain.',
                    776:             unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
                    777:             community => 'You are not permitted to request creation of a community this domain.',
                    778:             all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
                    779:         ); 
                    780:         $js .= <<END;
1.1       raeburn   781:     if (crschoice == 'official') {
                    782:         if (official != 1) {
                    783:             alert("$lt{'official'}");
                    784:             return false;
                    785:         }
                    786:     } else {
                    787:         if (crschoice == 'unofficial') {
1.41.2.1  raeburn   788:            if (unofficial != 1) {
                    789:                alert("$lt{'unofficial'}");
                    790:                return false;
1.1       raeburn   791:             }
                    792:         } else {
                    793:             if (crschoice == 'community') {
                    794:                 if (community != 1) {
                    795:                     alert("$lt{'community'}");
                    796:                     return false;
                    797:                 }
                    798:             } else {
                    799:                 if (actionchoice == 'new') {
                    800:                     alert("$lt{'all'}");
                    801:                     return false;
1.41.2.1  raeburn   802:                 }
1.1       raeburn   803:             }
                    804:         }
                    805:     }
                    806:     return true;
                    807: }
                    808: END
1.41.2.1  raeburn   809:     }
1.39      raeburn   810:     my ($pagetitle,$pageinfo,$domaintitle);
                    811:     if (ref($can_request) eq 'HASH') {
                    812:         if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
                    813:             if ($can_request->{'community'}) {
                    814:                 $pagetitle = 'Course/Community Requests';
                    815:                 $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
                    816:                 $domaintitle = &mt('Course/Community Domain');
                    817:             } else {
                    818:                 $pagetitle = 'Course Requests';
                    819:                 $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
                    820:                 $domaintitle = &mt('Course Domain');
                    821:             }
                    822:         } elsif ($can_request->{'community'}) {
1.40      raeburn   823:             $pagetitle = 'Community Requests';
                    824:             $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39      raeburn   825:             $domaintitle = &mt('Community Domain');
                    826:         } else {
                    827:             $pagetitle = 'Course/Community Requests';
                    828:             $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
                    829:             $domaintitle = &mt('Course/Community Domain');
                    830:         }
                    831:     }
1.41.2.1  raeburn   832: 
                    833:     if ($dom eq 'gcitest') {
                    834:         my $formname = 'requestcrs';
                    835:         my $nexttext = &mt('Continue');
                    836:         $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
                    837:             '<p>'.&mt('Deployment of a Concept Test requires completion of the following three steps:').'<ol>'.
                    838:             '<li>'.&mt('Creation of a course "container" and setting of access dates').'</li>'.
                    839:             '<li>'.&mt('Assembly of a valid test from Concept Inventory questions').'</li>'.
                    840:             '<li>'.&mt('Enrollment of students').'</li>'.
1.41.2.6  raeburn   841:             '</ol></p><p>'.&mt('When assembling a test you may:').
                    842:             '<br />'.&mt('(a) have a valid test built automatically by the WebCenter, or').'<br />'.&mt('(b) select the questions to include by combining questions chosen from eleven bins with four mandatory questions, or').
1.41.2.8  raeburn   843:             '<br />'.&mt('(c) copy one of your existing tests (including optional copying of the student roster)').'</p><p>'.&mt('The most efficient way to enroll students is to upload a text file containing usernames and passwords.').'<br />'.&mt("Students' e-mail addresses must be used as their usernames to ensure uniqueness.").'</p><div>'.
1.41.2.1  raeburn   844:             '<form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
                    845:             '<input type="hidden" name="state" value="courseinfo" />'."\n".
                    846:             '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
                    847:             '<input type="hidden" name="crstype" value="unofficial" />'."\n".
1.41.2.8  raeburn   848:             '<input type="hidden" name="reqaction" value="new" />'."\n".
1.41.2.1  raeburn   849:             '<input type="button" name="next" value="'.$nexttext.
                    850:             '" onclick="this.form.submit();" />'."\n".
                    851:             '</form></div>'.
                    852:              &Apache::loncommon::end_page());
                    853:         return;
                    854:     }
                    855: 
                    856:     if (!$onchange) {
                    857:         $r->print('&nbsp;<input type="submit" name="godom" value="'.
                    858:                    &mt('Change').'" />');
                    859:     }
                    860:     unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
                    861:         $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
                    862:                   &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
                    863:                   &Apache::loncommon::end_page());
                    864:         return;
                    865:     }
                    866: 
1.39      raeburn   867:     my @incdoms;
                    868:     if (ref($request_domains) eq 'HASH') {
                    869:         foreach my $item (keys(%{$request_domains})) {
                    870:             if (ref($request_domains->{$item}) eq 'ARRAY') {
                    871:                 foreach my $possdom (@{$request_domains->{$item}}) {
                    872:                     unless(grep(/^\Q$possdom\E$/,@incdoms)) {
                    873:                         push(@incdoms,$possdom);
                    874:                     } 
                    875:                 } 
                    876:             }
                    877:         }
                    878:     }
                    879:     $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
                    880:              '<p>'.$pageinfo.'</p>'.
1.34      raeburn   881:              '<div>'.
1.27      raeburn   882:               &Apache::lonhtmlcommon::start_pick_box().
1.39      raeburn   883:               &Apache::lonhtmlcommon::row_title($domaintitle).
1.1       raeburn   884:               '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.39      raeburn   885:               &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
1.1       raeburn   886:     if (!$onchange) {
                    887:         $r->print('&nbsp;<input type="submit" name="godom" value="'.
                    888:                    &mt('Change').'" />');
                    889:     }
1.39      raeburn   890:     unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
                    891:         $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
                    892:                   &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
                    893:                   &Apache::loncommon::end_page());
                    894:         return;
                    895:     }
1.27      raeburn   896:     $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2       raeburn   897:     my $formname = 'requestcrs';
1.1       raeburn   898:     my $nexttext = &mt('Next');
1.27      raeburn   899:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
                    900: <form name="mainmenu_action" method="post" action=""> 
1.41.2.8  raeburn   901: <select size="1" name="reqaction" >
1.2       raeburn   902:  <option value="new">'.&mt('New request').'</option>
1.1       raeburn   903:  <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
                    904:  <option value="log">'.&mt('View request history').'</option>
1.27      raeburn   905: </select></form>'.
                    906:               &Apache::lonhtmlcommon::row_closure(1).
1.39      raeburn   907:               &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27      raeburn   908: <form name="mainmenu_coursetype" method="post" action="">
1.39      raeburn   909: <select size="1" name="crstype">');
                    910:     if (ref($can_request) eq 'HASH') {
                    911:         if (keys(%{$can_request}) > 1) {
                    912:             $r->print(' <option value="any">'.&mt('All types').'</option>');
                    913:         }
                    914:         if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
                    915:             foreach my $type (@{$types}) {
                    916:                 next unless($can_request->{$type});
                    917:                 my $selected = '';
                    918:                 if ($env{'form.crstype'} eq '') {
                    919:                     if ($type eq 'official') {
                    920:                         $selected = ' selected="selected"';
                    921:                     }
                    922:                 } else {
                    923:                     if ($type eq $env{'form.crstype'}) {
                    924:                         $selected = ' selected="selected"';
                    925:                     }
                    926:                 }
                    927:                 $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
                    928:                           '</option>'."\n");
1.4       raeburn   929:             }
                    930:         }
                    931:     }
1.27      raeburn   932:     $r->print('</select></form>'."\n".
                    933:               &Apache::lonhtmlcommon::row_closure(1)."\n".
                    934:               &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38      raeburn   935:               '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27      raeburn   936:               '<input type="hidden" name="state" value="crstype" />'."\n".
                    937:               '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
                    938:               '<input type="hidden" name="crstype" value="" />'."\n".
1.41.2.8  raeburn   939:               '<input type="hidden" name="reqaction" value="" />'."\n".
1.27      raeburn   940:               '<input type="button" name="next" value="'.$nexttext.
                    941:               '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
                    942:               '</form></div>');
1.1       raeburn   943:     $r->print(&Apache::loncommon::end_page());
                    944:     return;
                    945: }
                    946: 
                    947: sub request_administration {
1.27      raeburn   948:     my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.36      raeburn   949:         $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
                    950:         $uname,$udom) = @_;
1.2       raeburn   951:     my $js;
1.16      raeburn   952:     if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2       raeburn   953:         $js =  <<END;
1.1       raeburn   954: 
                    955: function nextPage(formname,nextstate) {
                    956:     formname.state.value= nextstate;
                    957:     formname.submit();
                    958: }
1.16      raeburn   959: 
                    960: END
                    961:     }
                    962:     if (($action eq 'new') || ($action eq 'view')) {
                    963:         $js .= <<END;   
                    964: 
1.41.2.8  raeburn   965: function backPage(formname,prevstate,currstate) {
1.1       raeburn   966:     formname.state.value = prevstate;
1.41.2.8  raeburn   967:     if (currstate == "enrolling") {
                    968:         if (prevstate == "chooseitems" || prevstate == "uploadroster") {
                    969:             formname.action = "/adm/createuser";
                    970:         }
                    971:     } 
1.1       raeburn   972:     formname.submit();
                    973: }
                    974: 
                    975: END
1.2       raeburn   976:     }
                    977:     if ($action eq 'new') {
                    978:         my $jsextra;
1.31      raeburn   979:         if ($state eq 'courseinfo') {
1.2       raeburn   980:             $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31      raeburn   981:         } elsif ($state eq 'enrollment') {
                    982:             if (($env{'form.crstype'} eq 'official') && 
                    983:                 (&Apache::lonnet::auto_run('',$dom))) {
                    984:                 $js .= "\n".&section_check_javascript()."\n".&enrollment_lcsec_js();
                    985:             }
                    986:         } elsif ($state eq 'personnel') {
                    987:             $js .= "\n".&section_check_javascript()."\n".&personnel_lcsec_js();
1.41.2.2  raeburn   988:         } elsif (($state eq 'process') && ($env{'form.concepttest'} eq 'editmyown')) {
                    989:             $js .= "\n".&Apache::londocsgci::builder_javascript()."\n";
1.1       raeburn   990:         }
1.40      raeburn   991:         my $title;
                    992:         if ($env{'form.crstype'} eq 'community') {
                    993:             $title = 'Request a community';
1.41.2.8  raeburn   994:         } elsif (&Apache::loncommon::needs_gci_custom()) {
                    995:             $title = 'Create a new Concept Test';
1.40      raeburn   996:         } else {
                    997:             $title = 'Request a course';
                    998:         }
                    999:         $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
1.41.2.8  raeburn  1000:         return if (($state eq 'chooseitems') || ($state eq 'uploadroster') || 
                   1001:                    ($state eq 'enrolling'));
1.27      raeburn  1002:         &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.36      raeburn  1003:                             $codechk,$checkedcode,$description,$invalidcrosslist);
1.2       raeburn  1004:     } elsif ($action eq 'view') {
1.16      raeburn  1005:         my $jsextra;
                   1006:         my $formname = 'requestcrs';
                   1007:         my $prev = $states->{$action}[$page-1];
                   1008:         my $next = $states->{$action}[$page+1];
                   1009:         if ($state eq 'pick_request') {
                   1010:             $next = $states->{$action}[$page+1];
                   1011:             $jsextra = &viewrequest_javascript($formname,$next);
                   1012:         } elsif ($state eq 'details') {
                   1013:             $jsextra = &viewdetails_javascript($formname);
                   1014: 
                   1015:         } elsif ($state eq 'cancel') {
                   1016:             $jsextra = &viewcancel_javascript($formname);
                   1017:         }
1.40      raeburn  1018:         my $title;
                   1019:         if ($env{'form.crstype'} eq 'community') {
                   1020:             $title = 'Manage community requests';
                   1021:         } else {
                   1022:             $title = 'Manage course requests';
                   1023:         }
                   1024:         $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
1.16      raeburn  1025:         my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11      raeburn  1026:         if ($state eq 'pick_request') {
1.40      raeburn  1027:             my $title;
                   1028:             if ($env{'form.crstype'} eq 'community') {
                   1029:                 $title = &mt('Pending community requests');
                   1030:             } elsif ($env{'form.crstype'} eq 'official') {
                   1031:                 $title = &mt('Pending requests for official courses');
                   1032:             } elsif ($env{'form.crstype'} eq 'unofficial') {
                   1033:                 $title = &mt('Pending requests for unofficial courses');
                   1034:             } else {
                   1035:                 $title = &mt('Pending course/community requests'); 
                   1036:             }
                   1037:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.41.2.8  raeburn  1038:                       &print_request_status($dom,$action,$state).'</form></div>');
1.16      raeburn  1039:         } elsif ($state eq 'details') {
                   1040:             my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1041:             my $origcnum = $env{'form.cnum'};
                   1042:             if ($origcnum eq '') {
                   1043:                 $origcnum = $env{'form.origcnum'};   
                   1044:             }
                   1045:             if ($env{'form.crstype'} eq 'official') {
                   1046:                 &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1047:                                                          \%cat_order,\@code_order);
                   1048:             }
1.40      raeburn  1049:             my $title;
                   1050:             if ($env{'form.crstype'} eq 'community') {
                   1051:                 $title = &mt('Community Request Details');
                   1052:             } else {
                   1053:                 $title = &mt('Course Request Details');
                   1054:             }
                   1055:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.26      raeburn  1056:                       &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16      raeburn  1057:                                     \@code_order)."\n".
                   1058:                       '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
                   1059:             my @excluded = &get_excluded_elements($dom,$states,'new','review');
                   1060:             push(@excluded,'origcnum');
                   1061:             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
                   1062:             my $other = 'modify';
                   1063:             my %navtxt = &Apache::lonlocal::texthash (
                   1064:                                                       prev => 'Back',
                   1065:                                                       other => 'Modify Request',
                   1066:                                                       next => 'Cancel Request',
                   1067:                                                      );
1.31      raeburn  1068:             &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
                   1069:                                 $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16      raeburn  1070:             $r->print('</form>');
                   1071:         } elsif ($state eq 'cancel') {
1.40      raeburn  1072:             my $title;
                   1073:             if ($env{'form.crstype'} eq 'community') {
                   1074:                 $title = &mt('Cancel community request');
                   1075:             } else {
                   1076:                 $title = &mt('Cancel course request');
                   1077:             }
1.16      raeburn  1078:             my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40      raeburn  1079:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16      raeburn  1080:                       $output);
                   1081:             my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
                   1082:             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
                   1083:             my %navtxt = &Apache::lonlocal::texthash (
                   1084:                                                       prev => 'Back',
                   1085:                                                       next => 'Confirm Cancellation',
                   1086:                                                      );
                   1087:             if ($result eq 'ok') {
1.31      raeburn  1088:                 &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16      raeburn  1089:                                     $navtxt{'next'},$state);
                   1090:             } else {
1.31      raeburn  1091:                 &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
                   1092:                                     '',$state);
1.16      raeburn  1093:             }
                   1094:             $r->print('</form>');
                   1095:         } elsif ($state eq 'removal') {
                   1096:             my $cnum = $env{'form.origcnum'};
                   1097:             my $statuskey = 'status:'.$dom.':'.$cnum;
                   1098:             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                   1099:                                                    $env{'user.domain'},$env{'user.name'});
                   1100:             my $currstatus = $userreqhash{$statuskey};
                   1101:             my ($result,$error); 
                   1102:             if (($currstatus eq 'approval') || ($currstatus eq 'pending')) { 
                   1103:                 my %status = (
                   1104:                                  $statuskey => 'cancelled',
                   1105:                              );
                   1106:                 my $statusresult = &Apache::lonnet::put('courserequests',\%status);
                   1107:                 if ($statusresult eq 'ok') {
                   1108:                     my $delresult = 
                   1109:                         &Apache::lonnet::del_dom('courserequestqueue',
                   1110:                                                  [$cnum.'_'.$currstatus],$dom);
                   1111:                     if ($delresult eq 'ok') {
                   1112:                         $result = 'ok';
                   1113:                     } else {
                   1114:                         $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
                   1115:                     }
                   1116:                 } else {
                   1117:                     $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
                   1118:                 }
                   1119:             } else {
                   1120:                 $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');  
                   1121:             }
                   1122:             $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
                   1123:                       '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1.41.2.8  raeburn  1124:                       '<input type="hidden" name="reqaction" value="'.$action.'" />'."\n".
1.16      raeburn  1125:                       '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
                   1126:                       '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
                   1127:             if ($result eq 'ok') {
1.40      raeburn  1128:                 if ($env{'form.crstype'} eq 'community') {
                   1129:                     $r->print(&mt('Your community request has been cancelled.'));
                   1130:                 } else {
                   1131:                     $r->print(&mt('Your course request has been cancelled.'));
                   1132:                 }
1.16      raeburn  1133:             } else {
                   1134:                 $r->print('<div class="LC_error">'.
                   1135:                           &mt('The request cancellation process was not complete.').
                   1136:                           '<br />'.$error.'</div>');
                   1137:             }
                   1138:             $r->print('</form>');
1.11      raeburn  1139:         }
1.26      raeburn  1140:     } elsif ($action eq 'display') {
                   1141:         my $formname = 'requestcrs';
                   1142:         my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1143:         if ($env{'form.crstype'} eq 'official') {
                   1144:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1145:                                                      \%cat_order,\@code_order);
                   1146:         }
1.40      raeburn  1147:         my ($title,$header);
                   1148:         if ($env{'form.crstype'} eq 'community') {
                   1149:             $title = 'Community Request';
                   1150:             $header = &mt('Community Request');
                   1151:         } else {
                   1152:             $title = 'Course Request';
                   1153:             $header = &mt('Course Request');
                   1154:         }
                   1155:         $r->print(&header($title,'','','',{ 'only_body' => 1}).
                   1156:                   $crumb."\n".'<h3>'.$header.'</h3>'.
1.26      raeburn  1157:                   &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
                   1158:                                 \@code_order,$uname,$udom)."\n".'</div>'.
                   1159:                   &close_popup_form());
1.1       raeburn  1160:     } elsif ($action eq 'log') {
1.11      raeburn  1161:         $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1       raeburn  1162:     }
1.2       raeburn  1163:     $r->print(&Apache::loncommon::end_page());
1.1       raeburn  1164:     return;
                   1165: }
                   1166: 
1.31      raeburn  1167: sub enrollment_lcsec_js {
                   1168:     my %alerts = &section_check_alerts();
                   1169:     my $secname = $alerts{'badsec'};
                   1170:     my $secnone = $alerts{'reserved'};
                   1171:     my $output = '
                   1172: function validateEnrollSections(formname,nextstate) {
                   1173:     var badsectotal = 0;
                   1174:     var reservedtotal = 0;
                   1175:     var secTest = "";
                   1176: ';
                   1177:     for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   1178:         $output .= "
                   1179:     var selSec = 0;
                   1180:     for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
                   1181:         if (document.requestcrs.sec_".$i."[j].checked) {
                   1182:             selSec = document.requestcrs.sec_".$i."[j].value;
                   1183:         }
                   1184:         if (selSec == 1) {
                   1185:             secTest = validsection(document.requestcrs.loncapasec_".$i.");
                   1186:             if (secTest == 'badsec') {
                   1187:                 badsectotal++;
                   1188:             }
                   1189:             if (secTest == 'reserved') {
                   1190:                 reservedtotal++;
                   1191:             }
                   1192:         }
                   1193:     }
                   1194: ";
                   1195:     }
                   1196:     for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                   1197:         $output .= "
                   1198:     if (document.requestcrs.crosslist_".$i.".checked) {
                   1199:         secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
                   1200:         if (secTest == 'badsec') {
                   1201:             badsectotal++;
                   1202:         }
                   1203:         if (secTest == 'reserved') {
                   1204:             reservedtotal++;
                   1205:         }
                   1206:     }
                   1207: ";
                   1208:     }
                   1209:     $output .= "
                   1210:     if (badsectotal>0) {
                   1211:         alert('$secname');
                   1212:         return false;
                   1213:     }
                   1214:     if (reservedtotal>0) {
                   1215:         alert('$secnone');
                   1216:         return false;
                   1217:     }
                   1218:     formname.state.value= nextstate;
                   1219:     formname.submit();
                   1220:     return;
                   1221: }
                   1222: ";
                   1223:     return $output;
                   1224: }
                   1225: 
                   1226: sub personnel_lcsec_js {
                   1227:     my %alerts = &section_check_alerts();
                   1228:     my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
                   1229:     my $secnone = $alerts{'reserved'};
                   1230:     my $output = '
                   1231: function validatePersonnelSections(formname,nextstate) {
                   1232:     var badsectotal = 0;
                   1233:     var reservedtotal = 0;
                   1234:     var secTest = "";
                   1235: ';
                   1236:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1237:         $output .= "
                   1238:     if (document.requestcrs.person_".$i."_uname.value != '') {
                   1239:         secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
                   1240:         if (secTest == 'badsec') {
                   1241:             badsectotal++; 
                   1242:         }
                   1243:         if (secTest == 'reserved') {
                   1244:             reservedtotal++;
                   1245:         }
                   1246:     }
                   1247: ";
                   1248:     }
                   1249:     $output .= "
                   1250:     if (badsectotal > 0) {
                   1251:         alert('$secname');
                   1252:         return false;
                   1253:     } else {
                   1254:         if (reservedtotal > 0) {
                   1255:             alert('$secnone');
                   1256:             return false;
                   1257:         }
                   1258:     }
                   1259:     formname.state.value = nextstate;
                   1260:     formname.submit();
                   1261:     return;
                   1262: }
                   1263: ";
                   1264:     return $output;
                   1265: }
                   1266: 
                   1267: sub section_check_alerts {
                   1268:     my %lt = 
                   1269:         &Apache::lonlocal::texthash(
                   1270:             reserved => "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
                   1271:             badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
                   1272:             separate => 'Separate multiple sections with a comma.'
                   1273:         );
                   1274:     return %lt;
                   1275: }
                   1276: 
                   1277: sub section_check_javascript {
                   1278:     return <<"END";
                   1279: function validsection(field,mult) {
                   1280:     var str = field.value;
                   1281:     var badsec=0;
                   1282:     var reserved=0;
                   1283:     if (window.RegExp) {
                   1284:         var badsecnum=0;
                   1285:         var reservednum=0;
                   1286:         var pattern=/[^a-zA-Z0-9]/; 
                   1287:         str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
                   1288:         str = str.replace(/[ ]{2,}/gi," ");
                   1289:         if (mult == '1') {
                   1290:             var sections = new Array();
                   1291:             sections = str.split(/\\s*[\\s,;:]\\s*/);
                   1292:             var i;
                   1293:             for (i=0; i<sections.length; i++) {
                   1294:                 if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
                   1295:                     if (pattern.test(sections[i])) {
                   1296:                         badsecnum++;
                   1297:                     } else {
                   1298:                         if (sections[i] == 'none') {
                   1299:                             reservednum++;
                   1300:                         }
                   1301:                     }
                   1302:                 }
                   1303:             }
                   1304:         } else {
                   1305:             if ((str != '') && (str != undefined) && (str != null)) {
                   1306:                 if (pattern.test(str)) {
                   1307:                     badsecnum++;
                   1308:                 } else {
                   1309:                     if (str == 'none') {
                   1310:                         reservednum++;
                   1311:                     }
                   1312:                 }
                   1313:             }
                   1314:         }
                   1315:         if (badsecnum > 0) {
                   1316:             return 'badsec';
                   1317:         }
                   1318:         if (reservednum > 0) {
                   1319:             return 'reserved';
                   1320:         }
                   1321:     }
                   1322:     return;
                   1323: }
                   1324: END
                   1325: }
                   1326: 
1.26      raeburn  1327: sub close_popup_form {
                   1328:     my $close= &mt('Close Window');
                   1329:     return << "END";
                   1330: <p><form name="displayreq" action="" method="post">
                   1331: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
                   1332: </form></p>
                   1333: END
                   1334: }
                   1335: 
1.27      raeburn  1336: sub get_instcode {
                   1337:     my ($dom) = @_;
                   1338:     my ($instcode,$numtitles);
                   1339:     my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1340:     &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1341:                                              \%cat_order,\@code_order);
                   1342:     $numtitles = scalar(@codetitles);
                   1343:     if (@code_order > 0) {
                   1344:         my $message;
                   1345:         foreach my $item (@code_order) {
                   1346:             $instcode .= $env{'form.instcode_'.$item};
                   1347:         }
                   1348:     }
                   1349:     return ($instcode,$numtitles);
                   1350: }
                   1351: 
1.1       raeburn  1352: sub print_request_form {
1.27      raeburn  1353:     my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.36      raeburn  1354:         $description,$invalidcrosslist) = @_;
1.1       raeburn  1355:     my $formname = 'requestcrs';
1.2       raeburn  1356:     my ($next,$prev,$message,$output,$codepicker,$crstype);
                   1357:     $prev = $states->{$action}[$page-1];
                   1358:     $next = $states->{$action}[$page+1];
1.4       raeburn  1359:     my %navtxt = &Apache::lonlocal::texthash (
1.10      raeburn  1360:                                                prev => 'Back',
1.4       raeburn  1361:                                                next => 'Next',
                   1362:                                              );
1.2       raeburn  1363:     $crstype = $env{'form.crstype'};
1.34      raeburn  1364:     $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30      raeburn  1365:     my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
                   1366:         @disallowed);
1.1       raeburn  1367:     if ($crstype eq 'official') {
1.2       raeburn  1368:         if ($env{'form.instcode'} ne '') {
                   1369:             $instcode = $env{'form.instcode'};
1.27      raeburn  1370:         } elsif ($newinstcode ne '') {
                   1371:             $instcode = $newinstcode;
1.2       raeburn  1372:         }
1.27      raeburn  1373:         if ($checkedcode) {
                   1374:             if ($codechk eq 'valid') {
                   1375:                 $message = '<div class="LC_info">'.
                   1376:                            &mt('The chosen course category [_1] is valid.','<b>'.
                   1377:                            $instcode.'</b>').
                   1378:                            '<input type="hidden" name="instcode" value="'.
                   1379:                            $instcode.'" /></div>';
1.2       raeburn  1380:             } else {
                   1381:                 $message = '<div class="LC_warning">'.
1.27      raeburn  1382:                             &mt('No course was found matching your choice of institutional course category.');
                   1383:                 if ($codechk ne '') {
                   1384:                     $message .= '<br />'.$codechk;
                   1385:                 }
                   1386:                 $message .= '</div>';
1.2       raeburn  1387:                 $prev = 'crstype';
                   1388:             }
                   1389:             $r->print($message);
1.1       raeburn  1390:         }
1.2       raeburn  1391:     }
                   1392:     if ($prev eq 'crstype') {
1.4       raeburn  1393:         if ($crstype eq 'official') {
                   1394:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1395:                                                      \%cat_order,\@code_order);
                   1396:         }
1.2       raeburn  1397:         if (@code_order > 0) {
1.1       raeburn  1398:             $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
                   1399:                                            \%cat_titles,\%cat_order);
1.2       raeburn  1400:             if ($codepicker) {
1.34      raeburn  1401:                 $r->print(&mt('Specify the course to be created.').
                   1402:                           '<div>'.&Apache::lonhtmlcommon::start_pick_box().
                   1403:                           $codepicker.
1.2       raeburn  1404:                           &Apache::lonhtmlcommon::end_pick_box().'</div>');
                   1405:             } else {
1.20      raeburn  1406:                 $next = $states->{$action}[$page+2];
1.41.2.8  raeburn  1407:                 $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next));
1.2       raeburn  1408:             }
                   1409:         } else {
1.20      raeburn  1410:             if ($crstype eq 'official') {
                   1411:                 $next = $states->{$action}[$page+2];
                   1412:             }
1.41.2.8  raeburn  1413:             $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next));
1.1       raeburn  1414:         }
1.2       raeburn  1415:     } elsif ($prev eq 'codepick') {
1.27      raeburn  1416:         if ($instcode eq '') {
1.20      raeburn  1417:             $prev = $states->{$action}[$page-2];
                   1418:         }
1.41.2.8  raeburn  1419:         $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next,$description));
1.2       raeburn  1420:     } elsif ($state eq 'enrollment') {
1.4       raeburn  1421:         if ($crstype eq 'official') {
                   1422:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1423:                                                      \%cat_order,\@code_order);
                   1424:         }
1.41.2.8  raeburn  1425:         $r->print(&print_enrollment_menu($formname,$state,$instcode,$dom,\@codetitles,
1.27      raeburn  1426:                                          \%cat_titles,\%cat_order,\@code_order,
                   1427:                                          $invalidcrosslist));
1.2       raeburn  1428:     } elsif ($state eq 'personnel') {
1.41.2.8  raeburn  1429:         $r->print(&print_personnel_menu($dom,$formname,$state,$crstype,$invalidcrosslist));
1.4       raeburn  1430:     } elsif ($state eq 'review') {
1.30      raeburn  1431:         my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
                   1432:         my $now = time;
                   1433:         for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1434:             my $personname = $env{'form.person_'.$i.'_uname'};
                   1435:             my $persondom = $env{'form.person_'.$i.'_dom'};
                   1436:             if (($personname =~ /^$match_username$/) && 
                   1437:                 ($persondom =~ /^$match_domain$/)) {
                   1438:                 if (&Apache::lonnet::domain($persondom)) {
                   1439:                     my $personhome = 
                   1440:                         &Apache::lonnet::homeserver($personname,$persondom);
                   1441:                     if ($personhome eq 'no_host') {
                   1442:                         if ($persondom ne $dom) {
                   1443:                             my $skipuser = 1;
                   1444:                             if ($env{'user.role.dc./'.$persondom.'/'}) {
                   1445:                                 my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
                   1446:                                 if (((!$start) || ($start < $now)) && 
                   1447:                                     ((!$end) || ($end > $now))) {
                   1448:                                     $skipuser = 0;
                   1449:                                 }
                   1450:                             }
                   1451:                             if ($skipuser) {
                   1452:                                 push(@disallowed,$i);
                   1453:                                 $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
                   1454:                                 next;
                   1455:                             }
                   1456:                         }
                   1457:                         if (&get_cancreate_status($persondom,$personname,$dom)) {
                   1458:                             my ($allowed,$msg) = 
                   1459:                                 &check_newuser_rules($persondom,$personname,
                   1460:                                     \%alerts,\%rulematch,\%inst_results,
                   1461:                                     \%curr_rules,\%got_rules);
                   1462:                             if ($allowed) {
                   1463:                                 if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
                   1464:                                     if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
                   1465:                                         $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
                   1466:                                     }
                   1467:                                     if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
                   1468:                                         $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
                   1469:                                     }
                   1470:                                     if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
                   1471:                                         $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
                   1472:                                     }
                   1473:                                 }
                   1474:                             } else {
                   1475:                                 push(@disallowed,$i);
                   1476:                                 $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');  
                   1477:                             }
                   1478:                         } else {
                   1479:                             push(@disallowed,$i);
                   1480:                             $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
                   1481:                         }
                   1482:                     } else {
                   1483:                         my %userenv = 
                   1484:                             &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
                   1485:                         if ($env{'form.person_'.$i.'_lastname'} eq '') {
                   1486:                             $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
                   1487:                         }
                   1488:                         if ($env{'form.person_'.$i.'_firstname'} eq '') {
                   1489:                             $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
                   1490:                         }
                   1491:                         if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
                   1492:                             $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
                   1493:                         }
                   1494:                     }
                   1495:                 } elsif ($personname ne '') {
                   1496:                     push(@disallowed,$i);
                   1497:                     $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
                   1498:                 }
                   1499:             } elsif ($personname ne '') {
                   1500:                 push(@disallowed,$i);
                   1501:                 $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
                   1502:             }
                   1503:         }
1.16      raeburn  1504:         my $cnum;
                   1505:         if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
                   1506:             $cnum = $env{'form.origcnum'};
                   1507:         } else {
                   1508:             $cnum = &Apache::lonnet::generate_coursenum($dom);
                   1509:         }
1.4       raeburn  1510:         &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1511:                                                  \%cat_order,\@code_order);
1.40      raeburn  1512:         if ($crstype eq 'community') {
                   1513:             $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
                   1514:         } else {
                   1515:             $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
                   1516:         }
                   1517:         $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16      raeburn  1518:                   '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.40      raeburn  1519:         if ($crstype eq 'community') {
                   1520:             $navtxt{'next'} = &mt('Submit community request');
                   1521:         } else {
                   1522:             $navtxt{'next'} = &mt('Submit course request');
                   1523:         }
1.41.2.8  raeburn  1524:     } elsif ($state eq 'process') {
1.10      raeburn  1525:         if ($crstype eq 'official') {
                   1526:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1527:                                                      \%cat_order,\@code_order);
                   1528:         }
1.41.2.1  raeburn  1529:         my ($storeresult,$result) = &print_request_outcome($r,$dom,\@codetitles,
1.41.2.8  raeburn  1530:                                                            \@code_order,$formname);
1.13      raeburn  1531:         $r->print($result);
1.27      raeburn  1532:         if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
                   1533:             $r->print('<p>');
                   1534:             if ($storeresult eq 'ok') {
                   1535:                 $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
                   1536:                           &mt('Modify this request').'</a>'.('&nbsp;'x4));
                   1537:             }
1.41.2.2  raeburn  1538:             unless ($env{'form.concepttest'}) {
                   1539:                 $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
                   1540:             }
1.27      raeburn  1541:             return;
                   1542:         }
1.41.2.8  raeburn  1543:     } elsif ($state eq 'uploadroster') {
                   1544:          &roster_upload_form($r,$output,$formname);
1.1       raeburn  1545:     }
1.16      raeburn  1546:     my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24      raeburn  1547:     if ($state eq 'personnel') {
                   1548:         push(@excluded,'persontotal');
                   1549:     }
1.30      raeburn  1550:     if ($state eq 'review') {
                   1551:         if (@disallowed > 0) {
                   1552:             my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
                   1553:             my @currsecs = &current_lc_sections();
                   1554:             if (@currsecs) {
                   1555:                 push(@items,'sec');
                   1556:             }
                   1557:             my $count = 0;
                   1558:             for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1559:                 unless ($env{'form.person_'.$i.'_uname'} eq '') {
                   1560:                     if (grep(/^$i$/,@disallowed)) {
                   1561:                         foreach my $item (@items) {
                   1562:                             $env{'form.person_'.$i.'_'.$item} = '';
                   1563:                         }
                   1564:                     } else { 
                   1565:                         foreach my $item (@items) {
                   1566:                             $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
                   1567:                         }
                   1568:                     }
                   1569:                 }
                   1570:                 $count ++;
                   1571:             }
                   1572:             $env{'form.persontotal'} = $count;
                   1573:              
                   1574:         }
                   1575:     }
1.27      raeburn  1576:     if ($state eq 'enrollment') {
                   1577:         push(@excluded,'crosslisttotal');
                   1578:     }
1.41.2.8  raeburn  1579:     if ($state eq 'done') {
                   1580:         $r->print(&done_display());
                   1581:     } else {
                   1582:         $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded));
                   1583:         &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
                   1584:                             $navtxt{'next'},$state);
                   1585:     }
                   1586:     $r->print('</form>');
1.16      raeburn  1587:     return;
                   1588: }
                   1589: 
1.41.2.8  raeburn  1590: sub done_display {
                   1591:     return '<h3>'.&mt('Concept Test creation is complete').'</h3>'.
                   1592:            '<p>'.&mt('The following management tools are available via the "[_1]Manage Tests[_2]" tab, or from the toolbar on the [_3]Concept Test Contents[_4] page.[_5]',
                   1593:            '<a href="/adm/menu">','</a>','<a href="/adm/navmaps">','</a>','<br />').
                   1594:            '<dl class="LC_GCI_Menu">'.
                   1595:            '<dt>'.&mt('Concept Test Contents').'</dt>'.
                   1596:            '<dd style="background-image:url(\'/res/adm/pages/nav.png\');">'.&mt('Display the Table of Contents for your Concept Test.').'</dd>'.
                   1597:            '<dt>'.&mt('Assemble Concept Test').'</dt>'.
                   1598:            '<dd style="background-image:url(\'/res/adm/pages/docs.png\');">'.&mt('If no students have attempted the Concept Test you will be able to modify it. You can also change the start and end date of the test itself.').'</dd></dl>'.
                   1599:            '<dl class="LC_GCI_Menu">'.
                   1600:            '<dt>'.&mt('Enrollment and Student Activity').'</dt>'.
                   1601:            '<dd style="background-image:url(\'/res/adm/pages/cprv.png\');">'.&mt('Display or download a course roster, and view information about completion status and last login. You can also add new students, or change access dates for existing students.').'</dd>'.
                   1602:            '<dt>'.&mt("What's New?").'</dt>'.
                   1603:            '<dd style="background-image:url(\'/res/adm/pages/new.png\');">'.&mt('View information about changes in your Concept Test course.').'</dd></dl>'.
                   1604:            '<dl class="LC_GCI_Menu">'.
                   1605:            '<dt>'.&mt('Prepare Printable Concept Test').'</dt>'.
                   1606:            '<dd style="background-image:url(\'/res/adm/pages/prnt.png\');">'.&mt('Create a PDF which you can send to a printer to create a hardcopy of the Concept Test.').'</dd>'.
                   1607:            '<dt>'.&mt('Concept Test Statistics').'</dt>'.
                   1608:            '<dd style="background-image:url(\'/res/adm/pages/chrt.png\');">'.&mt('After the closing date of the Concept Test you can view and download statistics for the test, as well as anonymized submission data.').'</dd>'.
                   1609:            '</dl></p>';
                   1610: }
                   1611: 
1.30      raeburn  1612: sub get_cancreate_status {
                   1613:     my ($persondom,$personname,$dom) = @_;
                   1614:     my ($rules,$ruleorder) =
                   1615:         &Apache::lonnet::inst_userrules($persondom,'username');
                   1616:     my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
                   1617:                                                          $rules);
                   1618:     return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
                   1619: }
                   1620: 
                   1621: sub check_newuser_rules {
                   1622:     my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
                   1623:         $got_rules) = @_;
                   1624:     my $allowed = 1;
                   1625:     my $newuser = 1;
                   1626:     my ($checkhash,$userchkmsg);
                   1627:     my $checks = { 'username' => 1 };
                   1628:     $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
                   1629:     &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
                   1630:                                         $inst_results,$curr_rules,$got_rules);
                   1631:     if (ref($alerts->{'username'}) eq 'HASH') {
                   1632:         if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
                   1633:             my $domdesc =
                   1634:                 &Apache::lonnet::domain($persondom,'description');
                   1635:             if ($alerts->{'username'}{$persondom}{$personname}) {
                   1636:                 if (ref($curr_rules->{$persondom}) eq 'HASH') {
                   1637:                     $userchkmsg =
                   1638:                         &Apache::loncommon::instrule_disallow_msg('username',
                   1639:                                                                   $domdesc,1).
                   1640:                         &Apache::loncommon::user_rule_formats($persondom,
                   1641:                             $domdesc,$curr_rules->{$persondom}{'username'},
                   1642:                             'username');
                   1643:                 }
                   1644:                 $allowed = 0;
                   1645:             }
                   1646:         }
                   1647:     }
                   1648:     return ($allowed,$userchkmsg);
                   1649: }
                   1650: 
1.16      raeburn  1651: sub get_excluded_elements {
                   1652:     my ($dom,$states,$action,$state) = @_;
1.2       raeburn  1653:     my @excluded = ('counter');
                   1654:     my %elements = &form_elements($dom);
                   1655:     if (ref($states) eq 'HASH') {
                   1656:         if (ref($states->{$action}) eq 'ARRAY') {
                   1657:             my @items = @{$states->{$action}};
                   1658:             my $numitems = scalar(@items);
                   1659:             if ($numitems) {
                   1660:                 for (my $i=$numitems-1; $i>=0; $i--) {
                   1661:                     if (ref($elements{$action}) eq 'HASH') {
                   1662:                         if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16      raeburn  1663:                             foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2       raeburn  1664:                                 push(@excluded,$key);
                   1665:                             }
                   1666:                         }
                   1667:                     }
                   1668:                     last if ($items[$i] eq $state);
                   1669:                 }
                   1670:             }
                   1671:         }
                   1672:     }
                   1673:     if (grep(/^instcode_/,@excluded)) {
                   1674:         push(@excluded,'instcode');
1.1       raeburn  1675:     }
1.41.2.8  raeburn  1676:     if ($env{'form.initmap'}) {
                   1677:         push(@excluded,'initmap');
                   1678:     }
                   1679:     if ($env{'form.output'}) {
                   1680:         push(@excluded,'output');
                   1681:     }
1.16      raeburn  1682:     return @excluded;
1.1       raeburn  1683: }
                   1684: 
1.2       raeburn  1685: sub print_enrollment_menu {
1.41.2.8  raeburn  1686:     my ($formname,$state,$instcode,$dom,$codetitles,$cat_titles,$cat_order,
                   1687:         $code_order,$invalidcrosslist) =@_;
1.34      raeburn  1688:     my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2       raeburn  1689:     my $starttime = time;
1.41.2.8  raeburn  1690:     my $diff = 6*30*24*60*60; # 6 months from now, approx
                   1691:     if (&Apache::loncommon::needs_gci_custom()) {
                   1692:         $diff = 7*24*60*60; # 7 days from now, approx
                   1693:     }
                   1694:     my $endtime = $starttime+$diff;
1.2       raeburn  1695:     my %accesstitles = (
                   1696:                           'start' => 'Default start access',
1.16      raeburn  1697:                            'end'   => 'Default end access',
1.2       raeburn  1698:                        );
                   1699:     my %enrolltitles = (
                   1700:                            'start' => 'Start auto-enrollment',
                   1701:                            'end'   => 'End auto-enrollment',
                   1702:                        );
                   1703:     if ($env{'form.crstype'} eq 'official') {
                   1704:         if (&Apache::lonnet::auto_run('',$dom)) {
1.27      raeburn  1705:             $output = &show_invalid_crosslists($invalidcrosslist);
                   1706:             my ($section_form,$crosslist_form);
1.2       raeburn  1707:             $section_form = &inst_section_selector($dom,$instcode);
1.27      raeburn  1708:             if ($section_form) {
                   1709:                 $sections = &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  1710:                             '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
                   1711:                             '&nbsp;'.&mt('Sections for auto-enrollment').'</h3>'.
1.27      raeburn  1712:                             &Apache::lonhtmlcommon::row_closure(1).
                   1713:                             $section_form;
                   1714:             }
1.2       raeburn  1715:             my $crosslisttotal = $env{'form.crosslisttotal'};
1.24      raeburn  1716:             if (!$crosslisttotal) {
1.2       raeburn  1717:                 $crosslisttotal = 1;
                   1718:             }
                   1719:             if ($env{'form.addcrosslist'}) {
                   1720:                 $crosslisttotal ++;
                   1721:             }
                   1722:             for (my $i=0; $i<$crosslisttotal; $i++) {
                   1723:                 $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles, 
                   1724:                                                   $cat_titles,$cat_order,$i);
                   1725:             }
                   1726:             if ($crosslist_form) { 
                   1727:                 $crosslist_form .= 
1.40      raeburn  1728:                     &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2       raeburn  1729:                     '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
                   1730:                     '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1.41.2.8  raeburn  1731:                     ' onclick="javascript:nextPage(document.'.$formname.",'".$state.
1.27      raeburn  1732:                    "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
                   1733:                 $sections .=  &Apache::lonhtmlcommon::row_headline.
                   1734:                               '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
                   1735:                               &Apache::lonhtmlcommon::row_closure(1).
                   1736:                               $crosslist_form;
1.2       raeburn  1737:             }
1.34      raeburn  1738:             $hasauto = 1;
1.27      raeburn  1739:             $autoenroll = 
1.34      raeburn  1740:                 &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').'&nbsp;'.&mt('Add registered students automatically')).
1.2       raeburn  1741:                 '<span class="LC_nobreak"><label>'.
1.41.2.8  raeburn  1742:                 '<input type="radio" name="autoadds" value="1" />'.
1.2       raeburn  1743:                 &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
1.41.2.8  raeburn  1744:                 '<input type="radio" name="autoadds" value="0" checked="checked" />'.
1.2       raeburn  1745:                 &mt('No').'</label></span>'.
1.27      raeburn  1746:                 &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1747:                 &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').'&nbsp;'.&mt('Drop unregistered students automatically')).
1.2       raeburn  1748:                 '<span class="LC_nobreak"><label>'.
1.41.2.8  raeburn  1749:                 '<input type="radio" name="autodrops" value="1" />'.
1.2       raeburn  1750:                 &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
1.41.2.8  raeburn  1751:                 '<input type="radio" name="autodrops" value="0" checked="checked" />'.
1.2       raeburn  1752:                 &mt('No').'</label></span>'. 
1.27      raeburn  1753:                 &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1754:                 &date_setting_table($starttime,$endtime,$formname,'enroll',
1.41.2.9! raeburn  1755:                                     $hasauto,$dom,%enrolltitles);
1.2       raeburn  1756:         }
                   1757:     }
1.27      raeburn  1758:     my $access_dates = 
1.34      raeburn  1759:         &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1.41.2.9! raeburn  1760:                             $dom,%accesstitles);
1.27      raeburn  1761:     if ($sections) {
                   1762:         $output .=  $sections;
                   1763:     }
                   1764:     if ($autoenroll) {
                   1765:         $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
                   1766:                    '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
                   1767:                    &Apache::lonhtmlcommon::row_closure(1).
                   1768:                    $autoenroll;
                   1769:     }
                   1770:     if ($access_dates) {
                   1771:         my $header = &mt('Access dates for students');
                   1772:         if ($env{'form.crstype'} eq 'community') {
                   1773:             $header = &mt('Access dates for community members');
                   1774:         }
                   1775:         $output .= &Apache::lonhtmlcommon::row_headline('Access').
                   1776:                    '<h3>'.$header.'</h3>'.
1.41.2.9! raeburn  1777:                    &Apache::lonhtmlcommon::row_closure(1);
        !          1778:         if ($dom eq 'gcitest') {
        !          1779:             my $includeempty = 1;
        !          1780:             my $timezone = &Apache::lonlocal::gettimezone();
        !          1781:             $output .= &Apache::lonhtmlcommon::row_title('Time zone').
        !          1782:                        &Apache::loncommon::select_timezone('timezone',$timezone,
        !          1783:                                                            undef,$includeempty).
        !          1784:                        &Apache::lonhtmlcommon::row_closure(1);
        !          1785:         }
        !          1786:         $output .= $access_dates;
1.2       raeburn  1787:     }
1.41.2.1  raeburn  1788:     if ($dom eq 'gcitest') {
                   1789:         return $output;
                   1790:     } else {
                   1791:         return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
                   1792:                &Apache::lonhtmlcommon::end_pick_box().'</div>';
                   1793:     }
1.2       raeburn  1794: }
                   1795: 
1.27      raeburn  1796: sub show_invalid_crosslists {
                   1797:     my ($invalidcrosslist) = @_;
                   1798:     my $output;
                   1799:     if (ref($invalidcrosslist) eq 'ARRAY') {
                   1800:         if (@{$invalidcrosslist} > 0) {
                   1801:             $output = '<div class="LC_warning">'.
                   1802:                       &mt('The following crosslisted courses were invalid:').'<ul>';
                   1803:             foreach my $item (@{$invalidcrosslist}) {
                   1804:                 $output .= '<li>'.$item.'</li>';
                   1805:             }
                   1806:             $output .= '</ul></div><br />';
                   1807:         }
                   1808:     }
                   1809:     return $output;
                   1810: }
                   1811: 
                   1812: 
1.1       raeburn  1813: sub inst_section_selector {
1.2       raeburn  1814:     my ($dom,$instcode) = @_;
                   1815:     my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
                   1816:     my $sectotal = scalar(@sections);
1.1       raeburn  1817:     my $output;
1.2       raeburn  1818:     if ($sectotal) {
1.27      raeburn  1819:         $output .=  &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2       raeburn  1820:                     &Apache::loncommon::start_data_table().
                   1821:                     &Apache::loncommon::start_data_table_row().
                   1822:                     '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24      raeburn  1823:                     'value="'.$sectotal.'"  /></th>'.
1.2       raeburn  1824:                     '<th>'.&mt('Institutional Section').'</th>'.
1.34      raeburn  1825:                     '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
                   1826:                           '&nbsp;'.&mt('LON-CAPA section').'</th>'.
1.2       raeburn  1827:                     &Apache::loncommon::end_data_table_row();
                   1828:         for (my $i=0; $i<@sections; $i++) {
1.1       raeburn  1829:             my $colflag = $i%2;
1.31      raeburn  1830:             my $secon = ' checked="checked"';
                   1831:             my $secoff = '';
1.24      raeburn  1832:             if ($env{'form.origcnum'}) {
1.31      raeburn  1833:                 $secoff = $secon;
                   1834:                 $secon='';
1.24      raeburn  1835:             }
1.1       raeburn  1836:             $output .= &Apache::loncommon::start_data_table_row().
1.31      raeburn  1837:                        '<td><label><input type="radio" name="sec_'.$i.
                   1838:                        '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
                   1839:                        ('&nbsp;'x2).'<label><input type="radio" name="sec_'.$i.
                   1840:                         '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
                   1841:                        '<td align="center">'.$sections[$i].
1.1       raeburn  1842:                        '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2       raeburn  1843:                        $sections[$i].'" /></td>'.
1.1       raeburn  1844:                        '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2       raeburn  1845:                        '" value="'.$sections[$i].'" /></td>'.
1.1       raeburn  1846:                        &Apache::loncommon::end_data_table_row();
                   1847:         }
1.2       raeburn  1848:         $output .= &Apache::loncommon::end_data_table().
                   1849:                    &Apache::lonhtmlcommon::row_closure();
1.1       raeburn  1850:     }
                   1851:     return $output;
                   1852: }
                   1853: 
1.2       raeburn  1854: sub date_setting_table {
1.41.2.9! raeburn  1855:     my ($starttime,$endtime,$formname,$prefix,$hasauto,$dom,%datetitles) = @_;
1.2       raeburn  1856:     my ($perpetual,$table);
1.41.2.8  raeburn  1857:     my $no_hh_mm_ss = 1;
1.41.2.9! raeburn  1858:     my $hide_timezone;
1.41.2.8  raeburn  1859:     if (&Apache::loncommon::needs_gci_custom()) {
                   1860:         $no_hh_mm_ss = '';
1.41.2.9! raeburn  1861:         if ($dom eq 'gcitest') {
        !          1862:             if ($prefix eq 'access') {
        !          1863:                 $hide_timezone = 1;
        !          1864:             }
        !          1865:         }
1.41.2.8  raeburn  1866:     }
1.14      raeburn  1867:     my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.41.2.9! raeburn  1868:                                                         $starttime,'','','',$no_hh_mm_ss,'','','',1,$hide_timezone);
1.14      raeburn  1869:     my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.41.2.9! raeburn  1870:                                                       $endtime,'','','',$no_hh_mm_ss,'','','',1,$hide_timezone);
1.27      raeburn  1871:     my $closure = '';
1.14      raeburn  1872:     if ($prefix eq 'access') {
1.41.2.8  raeburn  1873:         unless (&Apache::loncommon::needs_gci_custom()) {
                   1874:             $perpetual = ' <span class="LC_nobreak"><label>'.
                   1875:                          '<input type="checkbox" name="no_end_date" />'.
                   1876:                          &mt('No end date').'</label></span>';
                   1877:         }
1.27      raeburn  1878:         $closure = '1';
1.2       raeburn  1879:     }
1.34      raeburn  1880: 
                   1881:     my %help_item = (
                   1882:                       access => {
                   1883:                                   start => 'Course_Request_Access_Start', 
                   1884:                                   end   => 'Course_Request_Access_End',
                   1885:                                 },
                   1886:                       enroll => {
                   1887:                                   start => 'Course_Request_Enroll_Start',
                   1888:                                   end   => 'Course_Request_Enroll_End',
                   1889:                                 },
                   1890:                      );
                   1891:     if ($hasauto) {
                   1892:         $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
                   1893:         $help_item{'access'}{'end'}   = 'Course_Request_RegAccess_End';
                   1894:     }
                   1895: 
                   1896:     $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
                   1897:              '&nbsp;'.$datetitles{'start'}).$startform.
1.27      raeburn  1898:              &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1899:              &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
                   1900:              '&nbsp;'.$datetitles{'end'}).$endform.$perpetual.
1.27      raeburn  1901:              &Apache::lonhtmlcommon::row_closure($closure);
1.2       raeburn  1902:     return $table;
                   1903: }
                   1904: 
                   1905: sub print_personnel_menu {
1.41.2.8  raeburn  1906:     my ($dom,$formname,$state,$crstype,$invalidcrosslist) = @_;
1.27      raeburn  1907:     my $output;
                   1908:     if ($crstype eq 'official') {
                   1909:         if (&Apache::lonnet::auto_run('',$dom)) {
                   1910:             $output .= &show_invalid_crosslists($invalidcrosslist);
                   1911:         }  
                   1912:     }
                   1913:     $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2       raeburn  1914:     my $persontotal = $env{'form.persontotal'};
1.16      raeburn  1915:     if ((!defined($persontotal)) || (!$persontotal)) {
1.2       raeburn  1916:         $persontotal = 1;
                   1917:     }
                   1918:     if ($env{'form.addperson'}) {
                   1919:         $persontotal ++;
                   1920:     }
1.13      raeburn  1921:     my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2       raeburn  1922: 
1.8       raeburn  1923:     my $type = 'Course';
                   1924:     if ($crstype eq 'community') {
                   1925:         $type = 'Community';
                   1926:     }
1.41      raeburn  1927:     my $roleoptions;
                   1928:     my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2       raeburn  1929:     foreach my $role (@roles) {
1.28      raeburn  1930:         my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2       raeburn  1931:         $roleoptions .= '  <option value="'.$role.'">'.$plrole.'</option>'."\n";
                   1932:     }
                   1933:     my %customroles=&Apache::lonuserutils::my_custom_roles();
                   1934:     if (keys(%customroles) > 0) {
                   1935:         foreach my $cust (sort(keys(%customroles))) {
1.28      raeburn  1936:             my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2       raeburn  1937:             $roleoptions .= '  <option value="'.$custrole.'">'.$cust.'</option>'."\n";
                   1938:         }
                   1939:     }
                   1940: 
1.30      raeburn  1941:     my @currsecs = &current_lc_sections();
1.2       raeburn  1942: 
                   1943:     my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
                   1944:     if (@currsecs) {
                   1945:         my $existsize = scalar(@currsecs);
                   1946:         if ($existsize > 3) {
                   1947:             $existsize = 3;
                   1948:         }
                   1949:         if ($existsize > 1) {
                   1950:             $existmult = ' multiple="multiple" size="'.$existsize.'" ';
                   1951:         }
                   1952:         @currsecs = sort { $a <=> $b } (@currsecs);
                   1953:         $existtitle = &mt('Official').':&nbsp;';
                   1954:         $existops = '<option value="">'.&mt('None').'</option>';
                   1955:         foreach my $sec (@currsecs) {
                   1956:             $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
                   1957:         }
                   1958:         $seccolspan = ' colspan="2"';
                   1959:         $newtitle = &mt('Other').':&nbsp;';
                   1960:     }
                   1961: 
1.27      raeburn  1962:     if ($persontotal) {
1.32      raeburn  1963:         my %lt = &Apache::lonlocal::texthash(
                   1964:             community => 'Requestor is automatically assigned Coordinator role.',
                   1965:             official => 'Requestor is automatically assigned Course Coordinator role.',
                   1966:         );
                   1967:         $lt{'unofficial'} = $lt{'official'};
1.27      raeburn  1968:         $output .= &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  1969:                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').'&nbsp;'.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27      raeburn  1970:     }
1.2       raeburn  1971:     for (my $i=0; $i<$persontotal; $i++) { 
                   1972:         my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
                   1973:         my $linkargstr = join("','",@linkargs);
1.29      raeburn  1974:         my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2       raeburn  1975:         my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29      raeburn  1976:                        "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2       raeburn  1977:         my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
                   1978:                                                             1,$onchange).
1.29      raeburn  1979:                         '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2       raeburn  1980:         my %form_elems;
                   1981:         foreach my $item (@items) {
                   1982:             next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
                   1983:             $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
                   1984:                                  'value="" readonly="readonly" />';
                   1985:         }
                   1986:         my $roleselector = '<select name="person_'.$i.'_role">'."\n".
                   1987:                            $roleoptions.'</select>';
                   1988:         my $sectionselector;
                   1989:         if (@currsecs) {
                   1990:             $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
                   1991:                                $existmult.'>'."\n".$existops.'</select>'.('&nbsp;' x3);
                   1992:         }
                   1993:         $sectionselector .= $newtitle.
1.14      raeburn  1994:             '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29      raeburn  1995:         my $usersrchlinktxt = &mt('Search for user');
                   1996:         my $usersrchlink =  &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
                   1997:                             $usersrchlinktxt);
                   1998:         my $userchklinktxt = &mt('Check username');
                   1999:         my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
                   2000:                             $userchklinktxt,'checkusername');
1.2       raeburn  2001:         $output .= 
1.29      raeburn  2002:             &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
                   2003:             '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
                   2004:             '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
                   2005:             &mt('Username').':&nbsp;'.$uname_form.'&nbsp;'.$userchklink.'</span><br />'."\n".
                   2006:             '<span class="LC_nobreak">'.&mt('Domain').':&nbsp;'.$udom_form.'</span></td>'.
                   2007:             '</tr>'."\n".'<tr>'.
1.13      raeburn  2008:             '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
                   2009:             '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
                   2010:             '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34      raeburn  2011:             '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').'&nbsp;'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
                   2012:             '<td'.$seccolspan.' align="center" valign="top">'.
                   2013:             &Apache::loncommon::help_open_topic('Course_Request_Rolesection').'&nbsp;'.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2       raeburn  2014:             '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
                   2015:     }
1.40      raeburn  2016:     $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2       raeburn  2017:                '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
                   2018:                '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1.41.2.8  raeburn  2019:                ' onclick="javascript:nextPage(document.'.$formname.",'".$state.
1.2       raeburn  2020:                "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40      raeburn  2021:                &Apache::lonhtmlcommon::end_pick_box().'</div>';
                   2022:     if ($crstype eq 'community') {
                   2023:         $output .= '<p>'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'</p>';
                   2024:     } else {
                   2025:         $output .= '<p>'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'</p>';
                   2026:     }
1.2       raeburn  2027:     return $output;
                   2028: }
                   2029: 
1.30      raeburn  2030: sub current_lc_sections {
                   2031:     my @currsecs;
                   2032:     if ($env{'form.sectotal'}) {
                   2033:         for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31      raeburn  2034:             if ($env{'form.sec_'.$i}) { 
                   2035:                 if (defined($env{'form.loncapasec_'.$i})) {
                   2036:                     my $lcsec = $env{'form.loncapasec_'.$i};
                   2037:                     unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
                   2038:                         push(@currsecs,$lcsec);
                   2039:                     }
1.30      raeburn  2040:                 }
                   2041:             }
                   2042:         }
                   2043:     }
                   2044:     return @currsecs;
                   2045: }
                   2046: 
1.1       raeburn  2047: sub print_request_status {
1.41.2.8  raeburn  2048:     my ($dom,$action,$state) = @_;
1.14      raeburn  2049:     my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
                   2050:                                            $env{'user.name'},'^status:'.$dom);
1.35      raeburn  2051:     my ($output,$formname,%queue_by_date);
1.37      raeburn  2052:     my ($types,$typenames) = &Apache::loncommon::course_types();
1.14      raeburn  2053:     foreach my $key (keys(%statusinfo)) {
                   2054:         if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { 
                   2055:             (undef,my($cdom,$cnum)) = split(':',$key);
                   2056:             next if ($cdom ne $dom);   
                   2057:             my $requestkey = $cdom.'_'.$cnum;
                   2058:             if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                   2059:                 my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                   2060:                                                        $env{'user.domain'},$env{'user.name'});
                   2061:                 my $entry;
                   2062:                 my $timestamp = $history{'reqtime'};
                   2063:                 my $crstype = $history{'crstype'};
                   2064:                 my $disposition = $history{'disposition'};
                   2065:                 next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
                   2066:                 next unless (($env{'form.crstype'} eq 'any') || 
                   2067:                             ($env{'form.crstype'} eq $crstype));
                   2068:                 next unless (($disposition eq 'approval') || 
                   2069:                              ($disposition eq 'pending'));
                   2070:                 if (ref($history{'details'}) eq 'HASH') {
                   2071:                     $entry = $requestkey.':'.$crstype.':'.
                   2072:                              &escape($history{'details'}{'cdescr'});
                   2073:                     if ($crstype eq 'official') {
                   2074:                         $entry .= ':'.&escape($history{'details'}{'instcode'}); 
                   2075:                     }
                   2076:                 }
                   2077:                 if ($entry ne '') {
                   2078:                     if (exists($queue_by_date{$timestamp})) {
                   2079:                         if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
                   2080:                             push(@{$queue_by_date{$timestamp}},$entry);
                   2081:                         }
                   2082:                     } else {
                   2083:                         @{$queue_by_date{$timestamp}} = ($entry);
1.10      raeburn  2084:                     }
                   2085:                 }
                   2086:             }
                   2087:         }
                   2088:     }
1.11      raeburn  2089:     $formname = 'requestcrs';
1.10      raeburn  2090:     my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.41.2.8  raeburn  2091:     $output = '<input type="hidden" name="reqaction" value="'.$action.'" />'."\n".
1.16      raeburn  2092: 
1.41.2.8  raeburn  2093:               '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1.16      raeburn  2094:               '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
                   2095:               '<input type="hidden" name="showdom" value="" />'."\n".
                   2096:               '<input type="hidden" name="cnum" value="" />'."\n";
1.10      raeburn  2097:     if (@sortedtimes > 0) {
1.40      raeburn  2098:         my $desctitle;
                   2099:         if ($env{'form.crstype'} eq 'any') {
                   2100:             $desctitle = &mt('Course/Community Description')
                   2101:         } elsif ($env{'form.crstype'} eq 'community') {
                   2102:             $desctitle = &mt('Community Description')
                   2103:         } else {
                   2104:             $desctitle = &mt('Course Description');
                   2105:         }
1.10      raeburn  2106:         $output .= &Apache::loncommon::start_data_table().
                   2107:                    &Apache::loncommon::start_data_table_header_row().
                   2108:                    '<th>'.&mt('Action').'</th>'.
1.40      raeburn  2109:                    '<th>'.$desctitle.'</th>'.
1.14      raeburn  2110:                    '<th>'.&mt('Domain').'</th>';
                   2111:         if ($env{'form.crstype'} eq 'any') {
1.10      raeburn  2112:             $output .= '<th>'.&mt('Type').'</th>';
                   2113:         }
1.14      raeburn  2114:         if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10      raeburn  2115:             $output .= '<th>'.&mt('Institutional Code').'</th>';
                   2116:         }
                   2117:         $output .= '<th>'.&mt('Date requested').'</th>'.
                   2118:                    &Apache::loncommon::end_data_table_header_row();
                   2119:         my $count = 0;
                   2120:         foreach my $item (@sortedtimes) {
                   2121:             my $showtime = &Apache::lonlocal::locallocaltime($item);
                   2122:             if (ref($queue_by_date{$item}) eq 'ARRAY') {
                   2123:                 foreach my $request (sort(@{$queue_by_date{$item}})) {
                   2124:                     my ($key,$type,$desc,$instcode) = split(':',$request);
                   2125:                     my ($cdom,$cnum) = split('_',$key);
                   2126:                     $output .= &Apache::loncommon::start_data_table_row().
1.16      raeburn  2127:      '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14      raeburn  2128:      '<td>'.&unescape($desc).'</td>'.
                   2129:      '<td>'.$cdom.'</td>';
                   2130:                     if ($env{'form.crstype'} eq 'any') {
1.35      raeburn  2131:                         my $typename;
                   2132:                         if (ref($typenames) eq 'HASH') {
                   2133:                             $typename = &mt($typenames->{$type});
                   2134:                         }
1.14      raeburn  2135:                         if ($typename eq '') {
                   2136:                             $typename = &mt('Unknown type');
                   2137:                         }
                   2138:                         $output .= '<td>'.$typename.'</td>';
1.10      raeburn  2139:                     }
1.14      raeburn  2140:                     if (($env{'form.crstype'} eq 'any') || 
1.10      raeburn  2141:                         ($env{'form.crstype'} eq 'official')) {
1.14      raeburn  2142:                         my $showinstcode;
                   2143:                         if ($type eq 'official') {
                   2144:                             $showinstcode = &unescape($instcode);
                   2145:                         } else {
                   2146:                             $showinstcode = &mt('Not applicable');
                   2147:                         }
                   2148:                         $output .= '<td>'.$showinstcode.'</td>';
1.10      raeburn  2149:                     }
                   2150:                     $output .= '<td>'.$showtime.'</td>'.
                   2151:                                &Apache::loncommon::end_data_table_row();
                   2152:                 }
                   2153:             }
                   2154:         }
                   2155:         $output .= &Apache::loncommon::end_data_table();
                   2156:     } else {
1.40      raeburn  2157:         if ($env{'form.crstype'} eq 'any') {
                   2158: $output .= '<div>'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
                   2159:         } elsif ($env{'form.crstype'} eq 'community') {
                   2160:             $output .= '<div>'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
                   2161:         } else {
                   2162:             $output .= '<div>'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
                   2163:         }
1.10      raeburn  2164:     }
                   2165:     $output .= '
1.30      raeburn  2166: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10      raeburn  2167:     return $output;
1.1       raeburn  2168: }
                   2169: 
1.16      raeburn  2170: sub print_cancel_request {
                   2171:     my ($dom,$cnum) = @_;
                   2172:     my $requestkey = $dom.'_'.$cnum;
                   2173:     my ($result,$output);
                   2174:     if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                   2175:         my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                   2176:                                                $env{'user.domain'},$env{'user.name'});
                   2177:         my $timestamp = $history{'reqtime'};
                   2178:         my $crstype = $history{'crstype'};
                   2179:         my $status = $history{'status'};
                   2180:         if (($status eq 'cancelled') || ($status eq 'created')) { 
                   2181:             if ($status eq 'cancelled') {
                   2182:                 $output = &mt('This request has already been cancelled.');
                   2183:             } elsif ($status eq 'created') {
                   2184:                 $output = &mt('This request has already been processed, and a course created.');
                   2185:             }
                   2186:             $output = &mt('No further action will be taken');
                   2187:         } elsif (ref($history{'details'}) eq 'HASH') {
1.37      raeburn  2188:             my ($types,$typename) = &Apache::loncommon::course_types();
1.16      raeburn  2189:             my $showtype = $crstype;
                   2190:             if (defined($typename->{$crstype})) {
                   2191:                 $showtype = $typename->{$crstype}; 
                   2192:             }
                   2193:             $output = '<p>'.&Apache::loncommon::start_data_table().
                   2194:                       &Apache::loncommon::start_data_table_header_row().
                   2195:                       '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
                   2196:                       '<th>'.&mt('Type').'</th>'.
                   2197:                       &Apache::loncommon::end_data_table_header_row().
                   2198:                       &Apache::loncommon::start_data_table_row().
                   2199:                       '<td>'.$history{details}{'cdescr'}.'</td><td>'.
                   2200:                       &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
                   2201:                       '<td>'.$showtype.'</td>'.
                   2202:                       &Apache::loncommon::end_data_table_row().
                   2203:                       &Apache::loncommon::end_data_table().
1.40      raeburn  2204:                       '<br /><div class="LC_warning">';
                   2205:             if ($crstype eq 'community') {
                   2206:                 $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
                   2207:             } else {
                   2208:                 $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
                   2209:             }
1.16      raeburn  2210:             $result = 'ok';
                   2211:         } else {
                   2212:             $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
                   2213:         }
                   2214:     } else {
                   2215:         $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
                   2216:     }
                   2217:     return ($result,$output);
                   2218: }
                   2219: 
                   2220: sub viewrequest_javascript {
                   2221:     my ($formname,$next) = @_;
                   2222:     return <<"ENDJS";
                   2223: 
                   2224: function chooseRequest(cdom,cnum) {
                   2225:     document.$formname.showdom.value = cdom;
                   2226:     document.$formname.cnum.value = cnum;
                   2227:     nextPage(document.$formname,'$next');
                   2228: }
                   2229: 
                   2230: ENDJS
                   2231: }
                   2232: 
                   2233: sub viewdetails_javascript {
                   2234:     my ($formname) = @_;
                   2235:     return << "ENDJS";
                   2236: 
                   2237: function nextPage(formname,nextstate) {
                   2238:     if (nextstate == "modify") { 
                   2239:         formname.state.value = "personnel";
1.41.2.8  raeburn  2240:         formname.reqaction.value = "new";
1.16      raeburn  2241:     } else {
                   2242:         formname.state.value = nextstate;
                   2243:     }
                   2244:     formname.submit();
                   2245: }
                   2246: 
                   2247: function backPage(formname,prevstate) {
                   2248:     formname.state.value = prevstate;
                   2249:     formname.submit();
                   2250: }
                   2251: 
                   2252: ENDJS
                   2253: }
                   2254: 
                   2255: sub viewcancel_javascript {
                   2256:     my $alert = &mt('Are you sure you want to cancel this request?\\n'.
                   2257:                     'Your request will be removed.');
                   2258:     return << "ENDJS";
                   2259: function nextPage(formname,nextstate) {
                   2260:     if (confirm('$alert')) {
                   2261:         formname.state.value = nextstate;
                   2262:         formname.submit();
                   2263:     }
                   2264:     return;
                   2265: }
                   2266: 
                   2267: ENDJS
                   2268: }
                   2269: 
1.1       raeburn  2270: sub print_request_logs {
1.10      raeburn  2271:     my ($jscript,$loaditems,$crumb) = @_;
1.1       raeburn  2272:     return;
                   2273: }
                   2274: 
                   2275: sub print_review {
1.30      raeburn  2276:     my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
                   2277:         $disallowed,$disallowmsg) = @_;
1.37      raeburn  2278:     my ($types,$typename) = &Apache::loncommon::course_types();
1.4       raeburn  2279:     my ($owner,$ownername,$owneremail);
1.26      raeburn  2280:     if ($uname eq '' || $udom eq '') {
                   2281:         $uname = $env{'user.name'};
                   2282:         $udom = $env{'user.domain'};
                   2283:     }
                   2284:     $owner = $uname.':'.$udom;
                   2285:     $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
                   2286:     my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4       raeburn  2287:     foreach my $email ('permanentemail','critnotification','notification') {
                   2288:         $owneremail = $emails{$email};
                   2289:         last if ($owneremail ne '');
                   2290:     }
                   2291:     my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
                   2292:         $section_headers,$section_values,$personnel_headers,$personnel_values);
                   2293: 
                   2294:     $crstypename = $env{'form.crstype'};
                   2295:     if (ref($typename) eq 'HASH') {
                   2296:         unless ($typename->{$env{'form.crstype'}} eq '') {
1.35      raeburn  2297:             $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4       raeburn  2298:         }
                   2299:     }
1.16      raeburn  2300:     my $category = 'Course';
                   2301:     if ($env{'form.crstype'} eq 'community') {
                   2302:         $category = 'Community';
                   2303:     }
1.4       raeburn  2304: 
                   2305:     $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
                   2306:     $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
                   2307: 
1.16      raeburn  2308:     my $enrollrow_title = &mt('Default Access Dates').'<br />'.
                   2309:                           '('.&Apache::lonnet::plaintext('st',$category).')';
1.4       raeburn  2310:     if ($env{'form.crstype'} eq 'official') {
                   2311:         if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
                   2312:             foreach my $title (@{$codetitles}) {
                   2313:                 if ($env{'form.instcode_'.$title} ne '') {
                   2314:                     $inst_headers .= '<th>'.$title.'</th>';
                   2315:                     my $longitem = $env{'form.instcode_'.$title};
                   2316:                     if (ref($cat_titles->{$title}) eq 'HASH') {
                   2317:                         if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
                   2318:                             $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
                   2319:                         }
                   2320:                     }
                   2321:                     $inst_values .= '<td>'.$longitem.'</td>';
                   2322:                 }
                   2323:             }
                   2324:         }
                   2325:         if (&Apache::lonnet::auto_run('',$dom)) {
1.16      raeburn  2326:             $enrollrow_title = &mt('Enrollment');
1.4       raeburn  2327:             $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
                   2328:                               '<th>'.&mt('Automatic Drops').'</th>'.
                   2329:                               '<th>'.&mt('Enrollment Starts').'</th>'.
                   2330:                               '<th>'.&mt('Enrollment Ends').'</th>';
                   2331:             $section_headers = '<th>'.&mt('Sections').'</th>'.
                   2332:                                '<th>'.&mt('Crosslistings').'</th>';
                   2333: 
1.13      raeburn  2334:             my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4       raeburn  2335:             my @autoroster = (&mt('No'),&mt('Yes'));
                   2336:             $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
                   2337:                              '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13      raeburn  2338:                              '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
                   2339:                              '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6       raeburn  2340:             $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
                   2341:                               &mt('Institutional section').'</th>'.
                   2342:                               '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5       raeburn  2343:             my $secinfo;
1.4       raeburn  2344:             if ($env{'form.sectotal'} > 0) {
                   2345:                 for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   2346:                     if ($env{'form.sec_'.$i}) {
1.5       raeburn  2347:                         $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4       raeburn  2348:                         if ($env{'form.loncapasec_'.$i} ne '') {
1.5       raeburn  2349:                             $secinfo .= $env{'form.loncapasec_'.$i};
                   2350:                         } else {
                   2351:                             $secinfo .= &mt('None');
1.4       raeburn  2352:                         }
1.5       raeburn  2353:                         $secinfo .= '</td></tr>';
1.4       raeburn  2354:                     }
                   2355:                 }
                   2356:             }
1.6       raeburn  2357:             if ($secinfo eq '') {
                   2358:                 $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5       raeburn  2359:             }
1.6       raeburn  2360:             $section_values .= $secinfo.'</table></td><td>'.
                   2361:                                '<table class="LC_innerpickbox"><tr><th>'.
                   2362:                                &mt('Institutional course/section').'</th>'.
                   2363:                                '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5       raeburn  2364:             my $xlistinfo;
1.24      raeburn  2365:             my $crosslisttotal = $env{'form.crosslisttotal'};
                   2366:             if (!$crosslisttotal) {
                   2367:                 $crosslisttotal = 1;
                   2368:             }
                   2369:             for (my $i=0; $i<$crosslisttotal; $i++) {
                   2370:                 if ($env{'form.crosslist_'.$i}) {
                   2371:                     $xlistinfo .= '<tr><td>';
                   2372:                     if (ref($code_order) eq 'ARRAY') {
                   2373:                         if (@{$code_order} > 0) {
                   2374:                             foreach my $item (@{$code_order}) {
                   2375:                                 $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4       raeburn  2376:                             }
                   2377:                         }
                   2378:                     }
1.24      raeburn  2379:                     $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
                   2380:                     if ($env{'form.crosslist_'.$i.'_lcsec'}) {
                   2381:                         $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
                   2382:                     } else {
                   2383:                         $xlistinfo .= &mt('None');
                   2384:                     }
                   2385:                     $xlistinfo .= '</td></tr>';
1.4       raeburn  2386:                 }
                   2387:             }
1.6       raeburn  2388:             if ($xlistinfo eq '') {
                   2389:                 $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5       raeburn  2390:             }
1.24      raeburn  2391:             $section_values .= $xlistinfo;
1.4       raeburn  2392:         }
1.24      raeburn  2393:         $section_values .= '</table></td>';
1.4       raeburn  2394:     }
                   2395: 
                   2396:     my %ctxt = &clone_text();
1.41.2.1  raeburn  2397:     if ($dom eq 'gcitest') {
                   2398:         $inst_headers .= '<th>'.&mt('Test Questions').'</th>';
                   2399:         my $concepttest;
                   2400:         if ($env{'form.concepttest'} eq 'defchosen') {
                   2401:             $concepttest = 'Auto-generated';
                   2402:         } elsif ($env{'form.concepttest'} eq 'editmyown') {
                   2403:             $concepttest = 'Manually selected';
1.41.2.6  raeburn  2404:         } elsif ($env{'form.concepttest'} eq 'cloning') {
                   2405:             $concepttest = 'Copied from existing test';
1.41.2.1  raeburn  2406:         }
1.41.2.6  raeburn  2407:         $inst_values .= '<td>'.$concepttest.('&nbsp;'x2).'</td>';
                   2408:     }
                   2409:     if (&show_cloneable()) {
                   2410:         $inst_headers .= '<th>'.&mt('Copy From').'</th>';
                   2411:         if ((($env{'form.cloning'}) || 
                   2412:              (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) &&
                   2413:             ($env{'form.clonecrs'} =~ /^$match_name$/) && 
1.41.2.1  raeburn  2414:             ($env{'form.clonedom'} =~ /^$match_domain$/)) {
                   2415:             my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39      raeburn  2416:                            $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
                   2417:                            $env{'form.crstype'});
1.41.2.1  raeburn  2418:             if ($canclone) {
                   2419:                 my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1.15      raeburn  2420:                               $env{'form.clonecrs'},('description','internal.coursecode'));
1.41.2.1  raeburn  2421:                 if (keys(%courseenv) > 0) {
1.41.2.6  raeburn  2422:                     if ($dom eq 'gcitest') {
                   2423:                         $inst_headers .= '<th>'.$ctxt{'ros'}.'</th>';
                   2424:                     } else {
                   2425:                         $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
                   2426:                     }
1.41.2.1  raeburn  2427:                     $inst_values .= '<td>'.$courseenv{'description'}.'&nbsp;';
                   2428:                     my $cloneinst = $courseenv{'internal.coursecode'};
                   2429:                     if ($cloneinst ne '') {
                   2430:                         $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
                   2431:                     } else {
1.41.2.6  raeburn  2432:                         unless ($dom eq 'gcitest') {
                   2433:                             $inst_values .= &mt('from').' '.$env{'form.clonedom'};
                   2434:                         }
1.41.2.1  raeburn  2435:                     }
1.41.2.6  raeburn  2436:                     $inst_values .= ('&nbsp;'x2).'</td><td>';
                   2437:                     if ($dom eq 'gcitest') {
                   2438:                         if ($env{'form.cloneroster'}) {
                   2439:                             $inst_values .= &mt('Yes');
                   2440:                         } else {
                   2441:                             $inst_values .= &mt('No');
                   2442:                         }
1.41.2.1  raeburn  2443:                     } else {
1.41.2.6  raeburn  2444:                         if ($env{'form.datemode'} eq 'preserve') {
                   2445:                             $inst_values .= $ctxt{'prd'}; 
                   2446:                         } elsif ($env{'form.datemode'} eq 'shift') {
                   2447:                             $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
                   2448:                         } else {
                   2449:                             $inst_values .= $ctxt{'ncd'};
                   2450:                         }
1.41.2.1  raeburn  2451:                     }
                   2452:                     $inst_values .= '</td>';
                   2453:                  } else {
                   2454:                      $inst_values .= '<td>'.&mt('Unknown').'</td>';
                   2455:                  }
1.15      raeburn  2456:              } else {
1.41.2.1  raeburn  2457:                  $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1.15      raeburn  2458:              }
1.41.2.1  raeburn  2459:         } else {
                   2460:             $inst_values .= '<td>'.&mt('None').'</td>';
                   2461:         }
1.4       raeburn  2462:     }
1.41.2.9! raeburn  2463:     my $tz;
        !          2464:     if ($dom eq 'gcitest') {
        !          2465:         if (&Apache::lonlocal::gettimezone($env{'form.timezone'}) ne 'local') {
        !          2466:             $tz = $env{'form.timezone'};
        !          2467:         } else {
        !          2468:             $tz = &Apache::lonlocal::gettimezone();
        !          2469:         }
        !          2470:         $enroll_headers .= '<th>'.&mt('Time Zone').'</th>';
        !          2471:     }
1.4       raeburn  2472:     $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
                   2473:                        '<th>'.&mt('Access Ends').'</th>';
1.41.2.9! raeburn  2474:     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend',$tz);
        !          2475:     if ($dom eq 'gcitest') {
        !          2476:         $enroll_values .= '<td>'.$tz.'</td>'; 
        !          2477:     }
        !          2478:     $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart,$tz).'</td>';
1.13      raeburn  2479:     if ($accessend == 0) {
1.4       raeburn  2480:         $enroll_values .= '<td>'.&mt('No end date').'</td>';
                   2481:     } else {
1.41.2.9! raeburn  2482:         $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend,$tz).'</td>';
1.4       raeburn  2483:     }
                   2484: 
                   2485:     my $container = 'Course';
1.41      raeburn  2486:     my $ccrole = 'cc';
1.4       raeburn  2487:     if ($env{'form.crstype'} eq 'community') {
                   2488:         $container = 'Community';
1.41      raeburn  2489:         $ccrole = 'co';
1.4       raeburn  2490:     }
                   2491: 
                   2492:     $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
                   2493:                          '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
                   2494:                          '</th>';
1.41      raeburn  2495: 
1.4       raeburn  2496:     $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41      raeburn  2497:                          '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4       raeburn  2498:                          '<td>'.&mt('None').'</td></tr>';
                   2499:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   2500:         if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30      raeburn  2501:             if (ref($disallowed) eq 'ARRAY') {
                   2502:                 next if (grep(/^$i$/,@{$disallowed}));
                   2503:             } 
1.31      raeburn  2504:             my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
                   2505:             my @allsecs;
                   2506:             foreach my $sec (@officialsecs) {
                   2507:                 next unless ($sec =~ /\w/);
                   2508:                 next if ($sec =~ /\W/);
                   2509:                 next if ($sec eq 'none');
                   2510:                 push(@allsecs,$sec);
                   2511:             }
1.14      raeburn  2512:             my $newsec = $env{'form.person_'.$i.'_newsec'};
                   2513:             $newsec =~ s/^\s+//;
                   2514:             $newsec =~s/\s+$//;
1.31      raeburn  2515:             my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14      raeburn  2516:             foreach my $sec (@newsecs) {
1.31      raeburn  2517:                 next unless ($sec =~ /\w/); 
1.14      raeburn  2518:                 next if ($sec =~ /\W/);
1.31      raeburn  2519:                 next if ($sec eq 'none');
1.14      raeburn  2520:                 if ($sec ne '') {
                   2521:                     unless (grep(/^\Q$sec\E$/,@allsecs)) {
                   2522:                         push(@allsecs,$sec); 
                   2523:                     }
                   2524:                 }
                   2525:             }
1.24      raeburn  2526:             my $showsec;
1.14      raeburn  2527:             if (@allsecs) {
                   2528:                 $showsec = join(', ',@allsecs);
                   2529:             }
1.24      raeburn  2530:             if ($showsec eq '') {
                   2531:                 $showsec = &mt('None');
                   2532:             }
1.41      raeburn  2533:             if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24      raeburn  2534:                 $showsec = &mt('None');
                   2535:             }
1.28      raeburn  2536:             my $role = $env{'form.person_'.$i.'_role'}; 
1.4       raeburn  2537:             $personnel_values .= 
1.13      raeburn  2538:                 '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
                   2539:                 $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4       raeburn  2540:                 '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
                   2541:                 $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28      raeburn  2542:                 '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14      raeburn  2543:                 '<td>'.$showsec.'</td></tr>';
1.4       raeburn  2544:         }
                   2545:     }
1.30      raeburn  2546:     my $output;
                   2547:     if (ref($disallowed) eq 'ARRAY') {
                   2548:         if (@{$disallowed} > 0) {
                   2549:             if (ref($disallowmsg) eq 'HASH') {
                   2550:                 $output = '<p class="LC_warning">'.
                   2551:                           &mt('Not all requested personnel could be included.').'<ul>'; 
                   2552:                 foreach my $item (@{$disallowed}) {
                   2553:                     $output .= '<li>'.$disallowmsg->{$item}.'</li>';
                   2554:                 }
                   2555:                 $output .= '</ul></p>';
                   2556:             }
                   2557:         }
                   2558:     }
                   2559:     $output .=    '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4       raeburn  2560:                   &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6       raeburn  2561:                   '<table class="LC_innerpickbox"><tr>'.
1.4       raeburn  2562:                   '<th>'.&mt('Name').'</th>'.
                   2563:                   '<th>'.&mt('Username:Domain').'</th>'.
                   2564:                   '<th>'.&mt('E-mail address').'</th>'.
                   2565:                   '</tr><tr>'."\n".
                   2566:                   '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
                   2567:                   '<td>'.$owneremail.'</td>'.
                   2568:                   '</tr></table>'."\n".
                   2569:                   &Apache::lonhtmlcommon::row_closure().
1.5       raeburn  2570:                   &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4       raeburn  2571:                   '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
                   2572:                   '<tr>'.$inst_values.'</tr></table>'."\n".
                   2573:                   &Apache::lonhtmlcommon::row_closure().
1.16      raeburn  2574:                   &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4       raeburn  2575:                   '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
                   2576:                   '<tr>'.$enroll_values.'</tr></table>'."\n".
                   2577:                   &Apache::lonhtmlcommon::row_closure();
                   2578:     if ($section_headers ne '') {
                   2579:         $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
                   2580:                    '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
                   2581:                    '<tr>'.$section_values.'</tr></table>'."\n".
                   2582:                    &Apache::lonhtmlcommon::row_closure();
                   2583:     }
                   2584:     $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
                   2585:                '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
                   2586:                $personnel_values.'</table>'."\n".
                   2587:                &Apache::lonhtmlcommon::row_closure(1).
1.26      raeburn  2588:                &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4       raeburn  2589:     return $output;
                   2590: }
                   2591: 
                   2592: sub dates_from_form {
1.41.2.9! raeburn  2593:     my ($startname,$endname,$timezone) = @_;
        !          2594:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname,$timezone);
        !          2595:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form($endname,$timezone);
1.13      raeburn  2596:     if ($endname eq 'accessend') {
1.4       raeburn  2597:         if (exists($env{'form.no_end_date'}) ) {
                   2598:             $enddate = 0;
                   2599:         }
                   2600:     }
                   2601:     return ($startdate,$enddate);
1.1       raeburn  2602: }
                   2603: 
                   2604: sub courseinfo_form {
1.41.2.8  raeburn  2605:     my ($dom,$formname,$state,$crstype,$next,$description) = @_;
1.32      raeburn  2606:     my %lt = &Apache::lonlocal::texthash(
                   2607:                 official => 'You must provide a (brief) course description.',
                   2608:                 community => 'You must provide a (brief) community description.'
                   2609:              );
                   2610:     $lt{'unofficial'} = $lt{'official'};
1.15      raeburn  2611:     my $js_validate = <<"ENDJS";
                   2612: <script type="text/javascript">
                   2613: // <![CDATA['
                   2614: 
                   2615: function validateForm() {
                   2616:     if ((document.$formname.cdescr.value == "")  || (document.$formname.cdescr.value == "undefined")) {
1.32      raeburn  2617:         alert('$lt{$crstype}');
1.15      raeburn  2618:         return;
                   2619:     }
                   2620:     nextPage(document.$formname,'$next');
                   2621: }
1.41.2.6  raeburn  2622: 
                   2623: function toggleCloning() {
                   2624:     var willclone;
                   2625:     if (document.$formname.cloning.length > 1) {
                   2626:         for (var i=0; i<document.$formname.cloning.length; i++) {
                   2627:             if (document.$formname.cloning[i].checked) {
                   2628:                 willclone = document.$formname.cloning[i].value;
                   2629:             }
                   2630:         }
                   2631:     }
                   2632:     if (willclone == 1) {
                   2633:         document.getElementById('cloneoptions').style.display="block";
                   2634:     } else {
                   2635:         document.getElementById('cloneoptions').style.display="none";
                   2636:         document.$formname.clonecrs.value = '';
                   2637:     }
                   2638: }
                   2639: 
1.15      raeburn  2640: // ]]
                   2641: </script>
                   2642: 
                   2643: ENDJS
1.27      raeburn  2644:     my $title = &mt('Brief Course Description');
1.41.2.1  raeburn  2645:     my $desctitle = &mt('Description');
                   2646:     if ($dom eq 'gcitest') {
                   2647:         $title = &mt('Concept Test Course Information');
                   2648:         $desctitle = &mt('Concept Test Title');
                   2649:     }
1.41.2.6  raeburn  2650:     my $clonetitle = &mt('Copy content and settings from an existing course?');
1.27      raeburn  2651:     if ($crstype eq 'community') {
                   2652:         $title = &mt('Brief Community Description');
1.41.2.6  raeburn  2653:         $clonetitle = &mt('Copy content and settings from an existing community?');
1.27      raeburn  2654:     }
1.41.2.6  raeburn  2655:     my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27      raeburn  2656:                   &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  2657:                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').'&nbsp;'.$title.'</h3>'.
1.27      raeburn  2658:                   &Apache::lonhtmlcommon::row_closure(1).
1.41.2.1  raeburn  2659:                   &Apache::lonhtmlcommon::row_title($desctitle).
1.41.2.9! raeburn  2660:                   '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.41.2.6  raeburn  2661:     my $showclone;
                   2662:     if ($dom eq 'gcitest') {
                   2663:         $showclone = &show_cloneable();
                   2664:     } else {
                   2665:         $showclone = 1;
                   2666:     }
1.41.2.1  raeburn  2667:     if ($dom eq 'gcitest') {
                   2668:         $output .= &Apache::lonhtmlcommon::row_closure(1).
1.41.2.6  raeburn  2669:                    &concepttest_form($showclone);
1.41.2.1  raeburn  2670:     }
1.13      raeburn  2671:     my ($home_server_pick,$numlib) =
                   2672:         &Apache::loncommon::home_server_form_item($dom,'chome',
                   2673:                                                   'default','hide');
                   2674:     if ($numlib > 1) {
                   2675:         $output .= &Apache::lonhtmlcommon::row_closure().
1.16      raeburn  2676:                    &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13      raeburn  2677:     }
                   2678:     $output .= $home_server_pick.
1.41.2.1  raeburn  2679:                &Apache::lonhtmlcommon::row_closure();
1.41.2.6  raeburn  2680:     if ($showclone && $dom ne 'gcitest') {
                   2681:         $output .= &Apache::lonhtmlcommon::row_headline().
                   2682:                    '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').'&nbsp;'.$clonetitle.
                   2683:                    '<label><input type="radio" name="cloning" value="1" '.
                   2684:                    'onclick="javascript:toggleCloning()" />'.
                   2685:                    &mt('Yes').('&nbsp;'x2).'</label><label>'.
                   2686:                    '<input type="radio" name="cloning" value="0" checked="checked"'.
                   2687:                    'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
                   2688:                    '</h3>'.
                   2689:                    &Apache::lonhtmlcommon::row_closure(1).
                   2690:                    &Apache::lonhtmlcommon::row_headline().
                   2691:                    '<div id="cloneoptions" style="display: none" >'.
                   2692:                    &Apache::lonhtmlcommon::start_pick_box().
                   2693:                    &clone_form($dom,$formname,$crstype).
                   2694:                    &Apache::lonhtmlcommon::end_pick_box().'</div>';
                   2695:     }
1.41.2.1  raeburn  2696:     if ($dom eq 'gcitest') {
                   2697:         my ($instcode,@codetitles,%cat_titles,%cat_order,@code_order);
                   2698:         my $invalidcrosslist = [];
1.41.2.8  raeburn  2699:         $output .= &print_enrollment_menu($formname,$state,$instcode,$dom,
1.41.2.1  raeburn  2700:                        \@codetitles,\%cat_titles,\%cat_order,
                   2701:                        \@code_order,$invalidcrosslist);
                   2702:     }
1.41.2.6  raeburn  2703:     $output .= &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1       raeburn  2704:     return $output;
                   2705: }
                   2706: 
1.41.2.1  raeburn  2707: sub concepttest_form {
1.41.2.6  raeburn  2708:     my ($showclone) = @_;
                   2709:     my $output = &Apache::lonhtmlcommon::row_title(&mt('Questions included in Concept Test')).
                   2710:                  '<label>'.
                   2711:                  '<input type="radio" name="concepttest" value="editmyown" checked="checked" /> '.
                   2712:                  &mt('Chosen by you from Concept Inventory').
                   2713:                  '</label><br />'.
                   2714:                  '<label>'.
                   2715:                  '<input type="radio" name="concepttest" value="defchosen" /> '.
                   2716:                  &mt('Automatically selected by WebCenter').
                   2717:                  '</label>';
                   2718:     if ($showclone) {
                   2719:         $output .=  '<br /><span class="LC_nobreak"><label>'.
                   2720:                     '<input type="radio" name="concepttest" value="cloning" /> '.
                   2721:                     &mt('Copied from existing Test: ').
                   2722:                     '</label>'.&select_oldtest().('&nbsp;' x2).
                   2723:                     '<input type="hidden" name="clonedom" value="gcitest" />'.
                   2724:                     '<label><input type="checkbox" value="1" name="cloneroster" />'.
                   2725:                     &mt('Copy roster').'</label>';
                   2726:     }
                   2727:     return $output;
                   2728: }
                   2729: 
                   2730: sub select_oldtest {
                   2731:     my $output = '<select name="clonecrs"><option value="" selected="selected">'.
                   2732:                  '</option>';
                   2733:     my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
                   2734:     my %Sortby;
                   2735:     foreach my $course (sort(keys(%courses))) {
                   2736:         next unless (ref($courses{$course}) eq 'HASH');
                   2737:         my $clean_title = $courses{$course}{'description'};
                   2738:         $clean_title =~ s/\W+//g;
                   2739:         if ($clean_title eq '') {
                   2740:             $clean_title = $courses{$course}{'description'};
                   2741:         }
                   2742:         push(@{$Sortby{$clean_title}},$course);
                   2743:     }
                   2744:     my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
                   2745:     foreach my $item (@sorted_courses) {
                   2746:         foreach my $course (@{$Sortby{$item}}) {
                   2747:             my ($cdom,$cnum) = split('_',$course);
                   2748:             if (($cdom eq 'gcitest') && (ref($courses{$course}) eq 'HASH')) {
                   2749:                 my $cdesc = $courses{$course}{'description'};
                   2750:                 $output .= '<option value="'.$cnum.'">'.$cdesc.'</option>';
                   2751:             }
                   2752:         }
                   2753:     }
                   2754:     $output .= '</select>';
                   2755:     return $output;
1.41.2.1  raeburn  2756: }
                   2757: 
1.1       raeburn  2758: sub clone_form {
                   2759:     my ($dom,$formname,$crstype) = @_;
                   2760:     my $type = 'Course';
                   2761:     if ($crstype eq 'community') {
                   2762:         $type = 'Community';
                   2763:     }
1.35      raeburn  2764:     my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').'&nbsp;'.
1.13      raeburn  2765:                     &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4       raeburn  2766:     my %lt = &clone_text();
1.2       raeburn  2767:     my $output .= 
                   2768:         &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29      raeburn  2769:         '<input type="text" size="25" name="clonecrs" value=""  />'.
1.35      raeburn  2770:         '</label>'.&Apache::lonhtmlcommon::row_closure(1).
                   2771:         &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
1.27      raeburn  2772:         $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2       raeburn  2773:         &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
                   2774:         '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
                   2775:         '</label><br /><label>'.
                   2776:         '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
                   2777:         '</label><br /><label>'.
                   2778:         '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
                   2779:         $lt{'shd'}.'</label>'.
                   2780:         '<input type="text" size="5" name="dateshift" value="365" />'.
1.27      raeburn  2781:         &Apache::lonhtmlcommon::row_closure(1);
1.1       raeburn  2782:     return $output;
                   2783: }
                   2784: 
1.16      raeburn  2785: sub clone_text {
1.4       raeburn  2786:     return &Apache::lonlocal::texthash(
                   2787:                'cid'  => 'Course ID',
                   2788:                'dmn'  => 'Domain',
                   2789:                'dsh'  => 'Date Shift',
                   2790:                'ncd'  => 'Do not clone date parameters',
1.41.2.6  raeburn  2791:                'prd'  => 'Copy date parameters as-is',
1.4       raeburn  2792:                'shd'  => 'Shift date parameters by number of days',
1.41.2.6  raeburn  2793:                'ros'  => 'Copy Roster',
1.4       raeburn  2794:         );
                   2795: }
                   2796: 
1.1       raeburn  2797: sub coursecode_form {
1.2       raeburn  2798:     my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1       raeburn  2799:     my $output;
1.2       raeburn  2800:     my %rowtitle = (
                   2801:                     instcode  => 'Course Category',
                   2802:                     crosslist => 'Cross Listed Course',
                   2803:                    );
1.34      raeburn  2804:     my %helpitem = ( 
                   2805:                      instcode => 'Course_Request_Category',
                   2806:                      crosslist => 'Course_Request_Crosslist',
                   2807:                    );
1.1       raeburn  2808:     if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
                   2809:         (ref($cat_order))) {
1.2       raeburn  2810:         my ($sel,$instsec,$lcsec);
                   2811:         $sel = $context;
                   2812:         if ($context eq 'crosslist') {
                   2813:             $sel .= '_'.$num;
                   2814:             $instsec = &mt('Institutional section').'<br />'.
                   2815:                        '<input type="text" size="10" name="'.$sel.'_instsec" />';
                   2816:             $lcsec = &mt('LON-CAPA section').'<br />'.
                   2817:                      '<input type="text" size="10" name="'.$sel.'_lcsec" />';
                   2818:         }
1.1       raeburn  2819:         if (@{$codetitles} > 0) {
                   2820:             my $lastitem = pop(@{$codetitles});
1.2       raeburn  2821:             my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                            $lastitem.'" />';
1.1       raeburn  2822:             if (@{$codetitles} > 0) {
1.34      raeburn  2823:                 $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).'&nbsp;'.$rowtitle{$context}).
1.2       raeburn  2824:                           '<table><tr>';
1.1       raeburn  2825:                 if ($context eq 'crosslist') {
1.2       raeburn  2826:                     $output .= '<td>'.&mt('Include?').'<br />'.
                   2827:                                '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1       raeburn  2828:                 }
                   2829:                 foreach my $title (@{$codetitles}) {
                   2830:                     if (ref($cat_order->{$title}) eq 'ARRAY') {
                   2831:                         if (@{$cat_order->{$title}} > 0) {
                   2832:                             $output .= '<td align="center">'.$title.'<br />'."\n".
                   2833:                                        '<select name="'.$sel.'_'.$title.'">'."\n".
                   2834:                                        ' <option value="" selected="selected">'.
                   2835:                                        &mt('Select').'</option>'."\n";
                   2836:                             foreach my $item (@{$cat_order->{$title}}) {
                   2837:                                 my $longitem = $item;
                   2838:                                 if (ref($cat_titles->{$title}) eq 'HASH') {
                   2839:                                     if ($cat_titles->{$title}{$item} ne '') {
                   2840:                                         $longitem = $cat_titles->{$title}{$item};
                   2841:                                     }
                   2842:                                 }
                   2843:                                 $output .= '<option value="'.$item.'">'.$longitem.
                   2844:                                            '</option>'."\n";
                   2845:                             }
                   2846:                         }
                   2847:                         $output .= '</select></td>'."\n";
                   2848:                     }
                   2849:                 }
                   2850:                 if ($context eq 'crosslist') {
                   2851:                     $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2       raeburn  2852:                                $lastinput.'</td><td align="center">'.$instsec.'</td>'.
                   2853:                                '<td align="center">'.$lcsec.'</td></tr></table>';
1.1       raeburn  2854:                 } else {
                   2855:                     $output .= '</tr></table>'.
                   2856:                                &Apache::lonhtmlcommon::row_closure().
                   2857:                                &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
                   2858:                                $lastinput;
                   2859:                 }
                   2860:             } else {
                   2861:                 if ($context eq 'crosslist') {
                   2862:                     $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2       raeburn  2863:                                '<table><tr>'.
                   2864:                                '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
                   2865:                                '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
                   2866:                                '</tr></table>';
1.1       raeburn  2867:                 } else { 
                   2868:                     $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
                   2869:                                $lastinput;
                   2870:                 }
                   2871:             }
1.2       raeburn  2872:             $output .=  &Apache::lonhtmlcommon::row_closure(1);
                   2873:             push(@$codetitles,$lastitem);    
                   2874:         } elsif ($context eq 'crosslist') {
                   2875:             $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
                   2876:                        '<table><tr><td align="center">'.
                   2877:                        '<span class="LC_nobreak">'.&mt('Include?').
                   2878:                        '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
                   2879:                        '</td><td align="center">'.&mt('Institutional ID').'<br />'.
                   2880:                        '<input type="text" size="10" name="'.$sel.'_instsec" />'.
                   2881:                        '</td><td align="center">'.$lcsec.'</td></tr></table>'.
                   2882:                        &Apache::lonhtmlcommon::row_closure(1);
1.1       raeburn  2883:         }
                   2884:     }
                   2885:     return $output;
                   2886: }
                   2887: 
                   2888: sub get_course_dom {
                   2889:     my $codedom = &Apache::lonnet::default_login_domain();
1.19      raeburn  2890:     if ($env{'form.showdom'} ne '') {
                   2891:         if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
                   2892:             return $env{'form.showdom'};
                   2893:         }
                   2894:     }
1.1       raeburn  2895:     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37      raeburn  2896:         my ($types,$typename) = &Apache::loncommon::course_types();
1.19      raeburn  2897:         if (ref($types) eq 'ARRAY') {
                   2898:             foreach my $type (@{$types}) {
                   2899:                 if (&Apache::lonnet::usertools_access($env{'user.name'},
                   2900:                                                       $env{'user.domain'},$type,
                   2901:                                                       undef,'requestcourses')) {
                   2902:                     return $env{'user.domain'};
                   2903:                 }
                   2904:             }
                   2905:             my @possible_doms;
                   2906:             foreach my $type (@{$types}) {
                   2907:                 my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
                   2908:                 if ($dom_str ne '') {
                   2909:                     my @domains = split(',',$dom_str);
                   2910:                     foreach my $entry (@domains) {
                   2911:                         my ($extdom,$extopt) = split(':',$entry);
                   2912:                         if ($extdom eq $env{'request.role.domain'}) {
                   2913:                             return $extdom;
                   2914:                         } 
                   2915:                         unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
                   2916:                             push(@possible_doms,$extdom);
                   2917:                         }
                   2918:                     }
                   2919:                 }
                   2920:             }
                   2921:             if (@possible_doms) {
                   2922:                 @possible_doms = sort(@possible_doms);
                   2923:                 return $possible_doms[0];
                   2924:             }
                   2925:         }
1.1       raeburn  2926:         $codedom = $env{'user.domain'};
                   2927:         if ($env{'request.role.domain'} ne '') {
                   2928:             $codedom = $env{'request.role.domain'};
                   2929:         }
                   2930:     }
                   2931:     return $codedom;
                   2932: }
                   2933: 
                   2934: sub display_navbuttons {
1.31      raeburn  2935:     my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1       raeburn  2936:     $r->print('<div class="LC_navbuttons">');
                   2937:     if ($prev) {
1.16      raeburn  2938:         $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31      raeburn  2939:                   'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16      raeburn  2940:                   ('&nbsp;'x3));
1.1       raeburn  2941:     } elsif ($prevtext) {
1.16      raeburn  2942:         $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
                   2943:                   'onclick="javascript:history.back()"/>'.('&nbsp;'x3));
                   2944:     }
                   2945:     if ($state eq 'details') {
                   2946:         $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31      raeburn  2947:                   'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16      raeburn  2948:                   ')" />');
1.1       raeburn  2949:     }
1.31      raeburn  2950:     my $gotnext;
1.15      raeburn  2951:     if ($state eq 'courseinfo') {
1.16      raeburn  2952:         $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   2953:                   'onclick="javascript:validateForm();" />');
1.31      raeburn  2954:         $gotnext = 1;
                   2955:     } elsif ($state eq 'enrollment') {
                   2956:         if (($env{'form.crstype'} eq 'official') && 
                   2957:             (&Apache::lonnet::auto_run('',$dom))) {
                   2958:             $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   2959:                       'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
                   2960:                 $gotnext = 1;
                   2961:         }
                   2962:     } elsif ($state eq 'personnel') {
                   2963:         if ($env{'form.persontotal'} > 0) { 
                   2964:             $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   2965:                       'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
                   2966:             $gotnext = 1;
                   2967:         }
                   2968:     }
                   2969:     unless ($gotnext) {
                   2970:         if ($next) {
                   2971:             $r->print('
                   2972:                       <input type="button" name="next" value="'.$nexttext.'" '.
                   2973:       'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
                   2974:         }
1.1       raeburn  2975:     }
                   2976:     $r->print('</div>');
                   2977: }
                   2978: 
                   2979: sub print_request_outcome {
1.41.2.8  raeburn  2980:     my ($r,$dom,$codetitles,$code_order,$formname) = @_;
1.13      raeburn  2981:     my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10      raeburn  2982:         %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24      raeburn  2983:     my $sectotal = $env{'form.sectotal'};
                   2984:     my $crosslisttotal = 0;
1.10      raeburn  2985:     $cnum = $env{'form.cnum'};
1.8       raeburn  2986:     unless ($cnum =~ /^$match_courseid$/) {
                   2987:         $output = &mt('Invalid LON-CAPA course number for the new course')."\n"; 
                   2988:         return $output;
                   2989:     }
1.11      raeburn  2990: 
1.10      raeburn  2991:     %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9       raeburn  2992:     if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   2993:         if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
                   2994:             $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
                   2995:         }
                   2996:     }
1.10      raeburn  2997:     $now = time;
                   2998:     $crstype = $env{'form.crstype'};
1.41      raeburn  2999:     my $ccrole = 'cc';
                   3000:     if ($crstype eq 'community') {
                   3001:         $ccrole = 'co';
                   3002:     }
1.17      raeburn  3003:     my @instsections;
1.8       raeburn  3004:     if ($crstype eq 'official') {
                   3005:         if (&Apache::lonnet::auto_run('',$dom)) {
1.13      raeburn  3006:             ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8       raeburn  3007:         }
1.10      raeburn  3008:         for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   3009:             if ($env{'form.sec_'.$i}) {
                   3010:                 if ($env{'form.secnum_'.$i} ne '') {
1.17      raeburn  3011:                     my $sec = $env{'form.secnum_'.$i};
                   3012:                     $sections{$i}{'inst'} = $sec;
                   3013:                     if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
                   3014:                         push(@instsections,$sec);
                   3015:                     }
1.13      raeburn  3016:                     $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.41.2.7  raeburn  3017:                     $sections{$i}{'loncapa'} =~ s/\W//g;
                   3018:                     if ($sections{$i}{'loncapa'} eq 'none') {
                   3019:                         $sections{$i}{'loncapa'} = '';
                   3020:                     }
1.10      raeburn  3021:                 }
                   3022:             }
                   3023:         }
                   3024:         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                   3025:             if ($env{'form.crosslist_'.$i}) {
                   3026:                 my $xlistinfo = '';
                   3027:                 if (ref($code_order) eq 'ARRAY') {
                   3028:                     if (@{$code_order} > 0) {
                   3029:                         foreach my $item (@{$code_order}) {
                   3030:                             $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
                   3031:                         }
                   3032:                     }
                   3033:                 }
1.22      raeburn  3034:                 $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24      raeburn  3035:                 if ($xlistinfo ne '') {
                   3036:                     $crosslisttotal ++;
                   3037:                 }
1.22      raeburn  3038:                 $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'}; 
1.13      raeburn  3039:                 $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10      raeburn  3040:             }
                   3041:         }
1.14      raeburn  3042:     } else {
                   3043:         $enrollstart = '';
                   3044:         $enrollend = '';
1.10      raeburn  3045:     }
                   3046:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   3047:         my $uname = $env{'form.person_'.$i.'_uname'};
1.16      raeburn  3048:         my $udom = $env{'form.person_'.$i.'_dom'};
1.10      raeburn  3049:         if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
                   3050:             if (&Apache::lonnet::domain($udom) ne '') {
1.13      raeburn  3051:                 unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
                   3052:                     $personnel{$uname.':'.$udom} = {
                   3053:                              firstname    => $env{'form.person_'.$i.'_firstname'},
                   3054:                              lastname     => $env{'form.person_'.$i.'_lastname'},
                   3055:                              emailaddr    => $env{'form.person_'.$i.'_emailaddr'},
                   3056:                                                    };
                   3057:                 }
                   3058:                 my $role = $env{'form.person_'.$i.'_role'};
                   3059:                 unless ($role eq '') {
1.16      raeburn  3060:                     if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13      raeburn  3061:                         my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
                   3062:                         unless (grep(/^\Q$role\E$/,@curr_roles)) {
                   3063:                             push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
                   3064:                         }
                   3065:                     } else {
                   3066:                         @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
                   3067:                     }
1.41      raeburn  3068:                     if ($role eq $ccrole) {
1.13      raeburn  3069:                         @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
                   3070:                     } else {
1.14      raeburn  3071:                         my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31      raeburn  3072:                         my @allsecs;
                   3073:                         foreach my $sec (@currsec) {
                   3074:                             next unless ($sec =~ /\w/);
                   3075:                             next if ($sec =~ /\W/);
                   3076:                             next if ($sec eq 'none');
                   3077:                             push(@allsecs,$sec);
                   3078:                         }
1.14      raeburn  3079:                         my $newsec = $env{'form.person_'.$i.'_newsec'};
                   3080:                         $newsec =~ s/^\s+//;
                   3081:                         $newsec =~s/\s+$//;
                   3082:                         my @newsecs = split(/[\s,;]+/,$newsec);
                   3083:                         foreach my $sec (@newsecs) {
                   3084:                             next if ($sec =~ /\W/);
1.31      raeburn  3085:                             next if ($sec eq 'none');
1.14      raeburn  3086:                             if ($sec ne '') {
1.31      raeburn  3087:                                 unless (grep(/^\Q$sec\E$/,@allsecs)) {
                   3088:                                     push(@allsecs,$sec);
1.13      raeburn  3089:                                 }
                   3090:                             }
                   3091:                         }
1.31      raeburn  3092:                         @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13      raeburn  3093:                     }
                   3094:                 }
1.10      raeburn  3095:             } else {
                   3096:                 push(@missingdom,$uname.':'.$udom);
                   3097:             }
                   3098:         } else {
                   3099:             push(@baduname,$uname.':'.$udom);
                   3100:         }
1.8       raeburn  3101:     }
1.41.2.9! raeburn  3102:     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend',$env{'form.timezone'});
1.14      raeburn  3103:     my $autodrops = 0;
                   3104:     if ($env{'form.autodrops'}) {
                   3105:         $autodrops = $env{'form.autodrops'}; 
                   3106:     }
                   3107:     my $autoadds = 0;
                   3108:     if ($env{'form.autoadds'}) {
                   3109:         $autodrops = $env{'form.autoadds'};
                   3110:     }
                   3111:     if ($env{'form.autoadds'}) {
                   3112:         $autodrops = $env{'form.autoadds'};
                   3113:     }
                   3114:     my $instcode = '';
                   3115:     if (exists($env{'form.instcode'})) {
                   3116:         $instcode = $env{'form.instcode'};
                   3117:     }
1.15      raeburn  3118:     my $clonecrs = '';
                   3119:     my $clonedom = '';
1.41.2.6  raeburn  3120:     if ((($env{'form.cloning'}) || 
                   3121:          (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) && 
                   3122:         ($env{'form.clonecrs'} =~ /^($match_courseid)$/) && 
1.15      raeburn  3123:         ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.41.2.6  raeburn  3124:         if ($dom eq 'gcitest') {
                   3125:             $env{'form.clonedom'} = 'gcitest';
                   3126:         }
1.16      raeburn  3127:         my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
                   3128:                                                     $env{'form.clonedom'});
1.41.2.6  raeburn  3129:         if ($clonehome ne 'no_host') {
1.16      raeburn  3130:             my $canclone =  
                   3131:                 &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39      raeburn  3132:                         $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
                   3133:                         $crstype);
1.15      raeburn  3134:             if ($canclone) {
                   3135:                 $clonecrs = $env{'form.clonecrs'};
                   3136:                 $clonedom = $env{'form.clonedom'};
                   3137:             }
                   3138:         }
                   3139:     }
1.8       raeburn  3140:     my $details = {
1.10      raeburn  3141:                     owner          => $env{'user.name'},
                   3142:                     domain         => $env{'user.domain'}, 
                   3143:                     cdom           => $dom,
1.11      raeburn  3144:                     cnum           => $cnum,
1.13      raeburn  3145:                     coursehome     => $env{'form.chome'},
                   3146:                     cdescr         => $env{'form.cdescr'},
1.10      raeburn  3147:                     crstype        => $env{'form.crstype'},
1.14      raeburn  3148:                     instcode       => $instcode,
1.15      raeburn  3149:                     clonedom       => $clonedom,
                   3150:                     clonecrs       => $clonecrs,
1.10      raeburn  3151:                     datemode       => $env{'form.datemode'},
1.14      raeburn  3152:                     dateshift      => $env{'form.dateshift'},
                   3153:                     sectotal       => $sectotal,
1.10      raeburn  3154:                     sections       => \%sections,
1.14      raeburn  3155:                     crosslisttotal => $crosslisttotal,
1.13      raeburn  3156:                     crosslists     => \%crosslistings,
1.14      raeburn  3157:                     autoadds       => $autoadds,
                   3158:                     autodrops      => $autodrops,
1.13      raeburn  3159:                     enrollstart    => $enrollstart,
                   3160:                     enrollend      => $enrollend,
                   3161:                     accessstart    => $accessstart,
                   3162:                     accessend      => $accessend,
1.10      raeburn  3163:                     personnel      => \%personnel,
1.8       raeburn  3164:                   };
1.41.2.2  raeburn  3165:     if ($dom eq 'gcitest') {
1.41.2.9! raeburn  3166:   
1.41.2.2  raeburn  3167:         if ($env{'form.concepttest'} eq 'editmyown') {
                   3168:             $details->{'firstres'} = 'nav'; 
                   3169:         } else {
                   3170:             $details->{'firstres'} = 'blank';
                   3171:         }
1.41.2.6  raeburn  3172:         if ($env{'form.concepttest'} eq 'cloning') {
                   3173:             if (($clonecrs) && ($clonedom eq 'gcitest')) {
                   3174:                 $details->{'cloneroster'} = $env{'form.cloneroster'};
                   3175:             } else {
                   3176:                 $details->{'clonedom'} = 'gci';
                   3177:                 $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
                   3178:             }
                   3179:         } else {
                   3180:             $details->{'clonedom'} = 'gci';
                   3181:             $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
                   3182:         }
1.41.2.2  raeburn  3183:         $details->{'datemode'} = 'delete';
                   3184:     }
1.41.2.8  raeburn  3185:     my (@inststatuses,$storeresult,$creationresult,$donedisplay);
1.9       raeburn  3186:     my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8       raeburn  3187:     if ($val eq '') {
                   3188:         if ($crstype eq 'official') {
1.19      raeburn  3189:             $output = &mt('You are not permitted to request creation of official courses.');
1.8       raeburn  3190:         } elsif ($crstype eq 'unofficial') {
1.19      raeburn  3191:             $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8       raeburn  3192:         } elsif ($crstype eq 'community') {
                   3193:             $output = &mt('You are not permitted to request creation of communities');
                   3194:         } else {
                   3195:             $output = &mt('Unrecognized course type: [_1]',$crstype);
                   3196:         }
1.27      raeburn  3197:         $storeresult = 'notpermitted'; 
1.8       raeburn  3198:     } else {
1.14      raeburn  3199:         my ($disposition,$message,$reqstatus);
1.8       raeburn  3200:         my %reqhash = (
1.14      raeburn  3201:                         reqtime   => $now,
1.10      raeburn  3202:                         crstype   => $crstype,
                   3203:                         details   => $details,
1.8       raeburn  3204:                       );
                   3205:         my $requestkey = $dom.'_'.$cnum;
1.17      raeburn  3206:         my $validationerror;
1.10      raeburn  3207:         if ($val eq 'autolimit=') {
                   3208:             $disposition = 'process';
                   3209:         } elsif ($val =~ /^autolimit=(\d+)$/) {
                   3210:             my $limit = $1;
1.8       raeburn  3211:             $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10      raeburn  3212:                                             $dom,$crstype,$limit,\$message);
1.8       raeburn  3213:         } elsif ($val eq 'validate') {
1.21      raeburn  3214:             my ($inststatuslist,$validationchk,$validation);
1.17      raeburn  3215:             if (@inststatuses > 0) {
                   3216:                 $inststatuslist = join(',',@inststatuses);
                   3217:             }
                   3218:             my $instseclist;
                   3219:             if (@instsections > 0) {
                   3220:                 $instseclist = join(',',@instsections);
                   3221:             }
1.21      raeburn  3222:             $validationchk = 
                   3223:                 &Apache::lonnet::auto_courserequest_validation($dom,
                   3224:                     $env{'user.name'}.':'.$env{'user.domain'},$crstype,
                   3225:                     $inststatuslist,$instcode,$instseclist);
                   3226:             if ($validationchk =~ /:/) {
                   3227:                 ($validation,$message) = split(':',$validationchk);
                   3228:             } else {
                   3229:                 $validation = $validationchk;
                   3230:             }
                   3231:             if ($validation =~ /^error(.*)$/) {
1.17      raeburn  3232:                 $disposition = 'approval';
                   3233:                 $validationerror = $1;
1.23      raeburn  3234:             } else {
                   3235:                 $disposition = $validation;
1.17      raeburn  3236:             }
1.8       raeburn  3237:         } else {
                   3238:             $disposition = 'approval';
                   3239:         }
1.14      raeburn  3240:         $reqhash{'disposition'} = $disposition;
                   3241:         $reqstatus = $disposition;
1.16      raeburn  3242:         my ($modified,$queued);
1.8       raeburn  3243:         if ($disposition eq 'rejected') {
1.40      raeburn  3244:             if ($crstype eq 'community') {
                   3245:                 $output = &mt('Your community request was rejected.');
                   3246:             } else {
                   3247:                 $output = &mt('Your course request was rejected.');
                   3248:             }
1.8       raeburn  3249:             if ($message) {
                   3250:                 $output .= '<div class="LC_warning">'.$message.'</div>';
                   3251:             }
1.27      raeburn  3252:             $storeresult = 'rejected';
1.8       raeburn  3253:         } elsif ($disposition eq 'process') {
1.14      raeburn  3254:             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
                   3255:             my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1.8       raeburn  3256:             my $type = 'Course';
                   3257:             if ($crstype eq 'community') {
                   3258:                 $type = 'Community';
                   3259:             }
1.41      raeburn  3260:             my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8       raeburn  3261:             foreach my $role (@roles) {
                   3262:                 $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
                   3263:             }
1.14      raeburn  3264:             my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
                   3265:                                    'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
                   3266:                                    \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
                   3267:             if ($result eq 'created') {
1.8       raeburn  3268:                 $disposition = 'created';
1.14      raeburn  3269:                 $reqstatus = 'created';
1.28      raeburn  3270:                 my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
                   3271:                                                            \%longroles);
1.40      raeburn  3272:                 if ($crstype eq 'community') {
                   3273:                     $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
                   3274:                 } else {
                   3275:                     $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
                   3276:                 }
1.41.2.2  raeburn  3277:                 if ($dom eq 'gcitest') {
                   3278:                     my $caller = 'requestcrs';
1.41.2.9! raeburn  3279:                     my $timezone;
        !          3280:                     if (&Apache::lonlocal::gettimezone($env{'form.timezone'}) ne 'local') {
        !          3281:                         $timezone = $env{'form.timezone'};
        !          3282:                     } else {
        !          3283:                         $timezone = Apache::lonlocal::gettimezone();
        !          3284:                     }
1.41.2.2  raeburn  3285:                     &acquire_cc_role($dom,$cnum,'cc./'.$dom.'/'.$cnum);
                   3286:                     my %parmresult =
                   3287:                         &store_crsparms($dom,$cnum,$now,$accessstart,$accessend);
                   3288:                     &Apache::londocsgci::setdefaults();
1.41.2.5  raeburn  3289:                     my %crsenvhash = (
                   3290:                                        suppress_tries => 'yes',
1.41.2.9! raeburn  3291:                                        timezone       => $timezone,
1.41.2.5  raeburn  3292:                                      );
                   3293:                     my $putresult =  &Apache::lonnet::put('environment',\%crsenvhash,$dom,$cnum);
1.41.2.6  raeburn  3294:                     if ($env{'form.concepttest'} eq 'cloning') {
                   3295:                         &Apache::lonuserstate::readmap($dom.'/'.$cnum);
                   3296:                         if (($clonecrs) && ($clonedom eq 'gcitest')) {
                   3297:                             my $cloneid = $clonedom.'/'.$clonecrs; 
                   3298:                             my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
                   3299:                             my $oldcdesc = $clonedesc{'description'};
                   3300:                             $output .= '<br />'.&mt('A concept test has been copied from your existing test: [_1].','<b>'.$oldcdesc.'</b>').'</p>';
                   3301:                             if ($env{'form.cloneroster'}) {
                   3302:                                 $output .= '<br />'.&mt('You requested copying of the old student roster to the new course.');
                   3303:                                 if ($logmsg =~ /\Q\0\E/) {
                   3304:                                     my @logging = split("\0",$logmsg);
                   3305:                                     if (@logging) {
                   3306:                                         $output .= '<p>'.$logging[-1].'</p>';
                   3307:                                     }
                   3308:                                 }
                   3309:                                 $output .= '<ul>'.
                   3310:                                            '<li>'.&mt('Access starts:').' '.
1.41.2.9! raeburn  3311:                                                   &Apache::lonlocal::locallocaltime($accessstart,$timezone).'</li>'.
        !          3312:                                            '<li>'.&mt('Access ends:').' '.&Apache::lonlocal::locallocaltime($accessend,$timezone).'</li>'.
1.41.2.8  raeburn  3313:                                            '</ul><br />';
1.41.2.6  raeburn  3314:                                 $r->print($output);
                   3315:                                 $output = '';
1.41.2.8  raeburn  3316:                                 $donedisplay = 1;
1.41.2.6  raeburn  3317:                             } else {
1.41.2.8  raeburn  3318:                                 &roster_upload_form($r,$output,$formname);
1.41.2.6  raeburn  3319:                                 $output = '';
                   3320:                             }
                   3321:                         } else {
                   3322:                             $output .= '</p>';
1.41.2.8  raeburn  3323:                             &roster_upload_form($r,$output,$formname);
1.41.2.6  raeburn  3324:                             $output = '';
                   3325:                         }
                   3326:                     } elsif ($env{'form.concepttest'} eq 'defchosen') {
1.41.2.2  raeburn  3327:                         $output .= '<br />';
                   3328:                         my $error = &Apache::londocsgci::store($caller,$dom,$cnum);
                   3329:                         if ($error) {
                   3330:                             $output .= '<span class="LC_error">'.
                   3331:                                        &mt('An error occurred saving an auto-generated concept test: [_1].',$error).
                   3332:                                        '</span>';
                   3333:                         } else {
                   3334:                             &Apache::lonuserstate::readmap($dom.'/'.$cnum);
                   3335:                             $output .= &mt('A concept test has also been generated.');
                   3336:                         }
1.41.2.6  raeburn  3337:                         $output .= '</p>';
1.41.2.8  raeburn  3338:                         &roster_upload_form($r,$output,$formname);
1.41.2.2  raeburn  3339:                         $output = '';
                   3340:                     } else {
1.41.2.8  raeburn  3341:                         $output .= '</p></form><br />'.&mt('The next step is to chose which questions are to be included in the Concept Test.').'<br /></p>';
1.41.2.2  raeburn  3342:                         $r->print($output);
                   3343:                         &Apache::londocsgci::editor($r,'requestcrs',$dom,$cnum);
                   3344:                         $output = '';
                   3345:                     }
                   3346:                 } else {
                   3347:                     $output .= '<br />'.$role_result.'</p>';
                   3348:                 }
1.27      raeburn  3349:                 $creationresult = 'created';
1.8       raeburn  3350:             } else {
1.40      raeburn  3351:                 $output = '<span class="LC_error">';
                   3352:                 if ($crstype eq 'community') {
                   3353:                     $output .= &mt('An error occurred when processing your community request.');
                   3354:                 } else {
                   3355:                     $output .= &mt('An error occurred when processing your course request.');
                   3356:                 }
                   3357:                 $output .= '<br />'.
                   3358:                            &mt('You may want to review the request details and submit the request again.').
1.14      raeburn  3359:                           '</span>';
1.27      raeburn  3360:                 $creationresult = 'error';
1.8       raeburn  3361:             }
                   3362:         } else {
                   3363:             my $requestid = $cnum.'_'.$disposition;
                   3364:             my $request = { 
                   3365:                             $requestid => {
                   3366:                                             timestamp   => $now,
                   3367:                                             crstype     => $crstype,
                   3368:                                             ownername   => $env{'user.name'},
                   3369:                                             ownerdom    => $env{'user.domain'},
1.13      raeburn  3370:                                             description => $env{'form.cdescr'}, 
1.8       raeburn  3371:                                           },
                   3372:                           };
1.16      raeburn  3373:             my $statuskey = 'status:'.$dom.':'.$cnum;
                   3374:             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                   3375:                                                    $env{'user.domain'},$env{'user.name'});
1.17      raeburn  3376:             if ($userreqhash{$statuskey} ne '') {
1.16      raeburn  3377:                 $modified = 1;
1.25      raeburn  3378:                 my $uname = &Apache::lonnet::get_domainconfiguser($dom);
                   3379:                 my %queuehash = &Apache::lonnet::get('courserequestqueue',
                   3380:                                                      [$cnum.'_approval',
                   3381:                                                       $cnum.'_pending'],$dom,$uname);
1.17      raeburn  3382:                 if (($queuehash{$cnum.'_approval'} ne '') || 
                   3383:                     ($queuehash{$cnum.'_pending'} ne '')) {
1.16      raeburn  3384:                     $queued = 1;
                   3385:                 }
                   3386:             }
                   3387:             unless ($queued) {
                   3388:                 my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
                   3389:                                                             $dom);
                   3390:                 if ($putresult eq 'ok') {
1.40      raeburn  3391:                     if ($crstype eq 'community') {
                   3392:                         $output .= &mt('Your community request has been recorded.');
                   3393:                     } else {
                   3394:                         $output .= &mt('Your course request has been recorded.') 
                   3395:                     }
                   3396:                     $output .= '<br />'.
1.16      raeburn  3397:                               &notification_information($disposition,$req_notifylist,
                   3398:                                                         $cnum,$now);
1.8       raeburn  3399:                 } else {
1.16      raeburn  3400:                     $reqstatus = 'domainerror';
                   3401:                     $reqhash{'disposition'} = $disposition;
                   3402:                     my $warning = &mt('An error occurred saving your request in the pending requests queue.');
                   3403:                     $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8       raeburn  3404:                 }
                   3405:             }
                   3406:         }
1.27      raeburn  3407:         my ($statusresult);
1.10      raeburn  3408:         if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                   3409:             $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
                   3410:                                                            'courserequests');
1.14      raeburn  3411:             if ($storeresult eq 'ok') {
                   3412:                 my %status = (
                   3413:                                  'status:'.$dom.':'.$cnum => $reqstatus,
                   3414:                              );
1.27      raeburn  3415:                 $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14      raeburn  3416:             }
1.10      raeburn  3417:         } else {
                   3418:             $storeresult = 'error: invalid requestkey format'; 
                   3419:         }
1.8       raeburn  3420:         if ($storeresult ne 'ok') {
1.13      raeburn  3421:             $output .=  '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
                   3422:             &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14      raeburn  3423:         } elsif ($statusresult ne 'ok') {
1.28      raeburn  3424:             $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
1.14      raeburn  3425:             &Apache::lonnet::logthis("Error saving course request status for  $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8       raeburn  3426:         }
1.16      raeburn  3427:         if ($modified && $queued && $storeresult eq 'ok') {
1.40      raeburn  3428:             if ($crstype eq 'community') {
                   3429:                 $output .= '<p>'.&mt('Your community request has been updated').'</p>';
                   3430:             } else {
                   3431:                 $output .= '<p>'.&mt('Your course request has been updated').'</p>';
                   3432:             }
                   3433:             $output .= &notification_information($disposition,$req_notifylist,$cnum,$now);
1.16      raeburn  3434:         }
1.17      raeburn  3435:         if ($validationerror ne '') {
1.19      raeburn  3436:             $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17      raeburn  3437:         }
1.16      raeburn  3438:     }
1.27      raeburn  3439:     if ($creationresult ne '') {
1.41.2.8  raeburn  3440:         if ($donedisplay) {
                   3441:             $r->print('<br />'.&done_display());
                   3442:         }
1.27      raeburn  3443:         return ($creationresult,$output);
                   3444:     } else {
                   3445:         return ($storeresult,$output);
                   3446:     }
1.16      raeburn  3447: }
                   3448: 
1.28      raeburn  3449: sub update_requestors_roles {
                   3450:     my ($dom,$cnum,$crstype,$details,$longroles) = @_;
                   3451:     my $now = time;
                   3452:     my ($active,$future,$numactive,$numfuture,$output);
                   3453:     my $owner = $env{'user.name'}.':'.$env{'user.domain'};
                   3454:     if (ref($details) eq 'HASH') {
                   3455:         if (ref($details->{'personnel'}) eq 'HASH') {
1.41      raeburn  3456:             my $ccrole = 'cc';
                   3457:             if ($crstype eq 'community') {
                   3458:                 $ccrole = 'co';
                   3459:             }
1.35      raeburn  3460:             unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
                   3461:                 $details->{'personnel'}{$owner} = {
1.41      raeburn  3462:                                                     'roles' => [$ccrole],
                   3463:                                                     $ccrole => { 'usec' => [] },
1.35      raeburn  3464:                                                   };
                   3465:             }
                   3466:             my @roles;
                   3467:             if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
                   3468:                 @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41      raeburn  3469:                 unless (grep(/^\Q$ccrole\E$/,@roles)) {
                   3470:                     push(@roles,$ccrole);
1.35      raeburn  3471:                 }
                   3472:             } else {
1.41      raeburn  3473:                 @roles = ($ccrole);
1.35      raeburn  3474:             }
                   3475:             foreach my $role (@roles) {
1.41.2.3  raeburn  3476:                 my $refresh=$env{'user.refresh.time'};
                   3477:                 if ($refresh eq '') {
                   3478:                     $refresh = $env{'user.login.time'};
                   3479:                 }
                   3480:                 if ($refresh eq '') {
                   3481:                     $refresh = $now;
                   3482:                 }
                   3483:                 my $start = $refresh-1;
1.35      raeburn  3484:                 my $end = '0';
                   3485:                 if ($role eq 'st') {
                   3486:                     if ($details->{'accessstart'} ne '') {
                   3487:                         $start = $details->{'accessstart'};
                   3488:                     }
                   3489:                     if ($details->{'accessend'} ne '') {
                   3490:                         $end = $details->{'accessend'};
                   3491:                     }
                   3492:                 }
                   3493:                 my @usecs;
1.41      raeburn  3494:                 if ($role ne $ccrole) {
1.35      raeburn  3495:                     if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
                   3496:                         @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
                   3497:                     }
                   3498:                 } 
                   3499:                 if ($role eq 'st') {
                   3500:                     if (@usecs > 1) {
                   3501:                         my $firstsec = $usecs[0];
                   3502:                         @usecs = ($firstsec);
                   3503:                     }
                   3504:                 }
                   3505:                 if (@usecs == 0) {
                   3506:                     push(@usecs,'');
                   3507:                 }
                   3508:                 foreach my $usec (@usecs) {
                   3509:                     my (%userroles,%newrole,%newgroups,$spec,$area);
                   3510:                     my $area = '/'.$dom.'/'.$cnum;
                   3511:                     my $spec = $role.'.'.$area;
                   3512:                     if ($usec ne '') {
                   3513:                        $spec .= '/'.$usec;
                   3514:                        $area .= '/'.$usec;
                   3515:                     }
                   3516:                     if ($role =~ /^cr\//) {
                   3517:                         &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
                   3518:                                                           $cnum,$spec,$area);
                   3519:                     } else {
                   3520:                         &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
                   3521:                                                             $spec,$cnum,$area);
1.28      raeburn  3522:                     }
1.35      raeburn  3523:                     &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
                   3524:                                                    \%newgroups);
                   3525:                     $userroles{'user.role.'.$spec} = $start.'.'.$end;
                   3526:                     &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
                   3527:                     if (($end == 0) || ($end > $now)) {
                   3528:                         my $showrole = $role;
1.28      raeburn  3529:                         if ($role =~ /^cr\//) {
1.35      raeburn  3530:                             $showrole = &Apache::lonnet::plaintext($role,$crstype);
                   3531:                         } elsif (ref($longroles) eq 'HASH') {
                   3532:                             if ($longroles->{$role} ne '') {
                   3533:                                 $showrole = $longroles->{$role};
                   3534:                             }
1.28      raeburn  3535:                         }
1.35      raeburn  3536:                         if ($start <= $now) {
                   3537:                             $active .= '<li><a href="/adm/roles?selectrole=1&'.
                   3538:                                        $spec.'=1">'.$showrole;
                   3539:                             if ($usec ne '') {
                   3540:                                 $active .= ' - '.&mt('section:').' '.$usec; 
1.28      raeburn  3541:                             }
1.35      raeburn  3542:                             $active .= '</a></li>';
                   3543:                             $numactive ++;
                   3544:                         } else { 
                   3545:                             $future .= '<li>'.$showrole;
                   3546:                             if ($usec ne '') {
                   3547:                                 $future .= ' - '.&mt('section:').' '.$usec;
1.28      raeburn  3548:                             }
1.35      raeburn  3549:                             $future .= '</li>';
                   3550:                             $numfuture ++;
1.28      raeburn  3551:                         }
                   3552:                     }
                   3553:                 }
                   3554:             }
                   3555:         }
                   3556:     }
                   3557:     if ($active) {
                   3558:         if ($numactive == 1) {
1.41      raeburn  3559:             if ($crstype eq 'Community') {
                   3560:                 $output = &mt('Use the following link to enter the community:');
                   3561:             } else {
                   3562:                 $output = &mt('Use the following link to enter the course:'); 
                   3563:             }
1.28      raeburn  3564:         } else {
1.41      raeburn  3565:             if ($crstype eq 'Community') {
                   3566:                 $output = &mt('Use the following links to your new roles to enter the community:');
                   3567:             } else {
                   3568:                 $output = &mt('Use the following links to your new roles to enter the course:');
                   3569:             }
1.28      raeburn  3570:         }
                   3571:         $output .= ' <ul>'.$active.'</ul><br />';
                   3572:     }
                   3573:     if ($future) {
1.41      raeburn  3574:         if ($crstype eq 'Community') {
                   3575:             $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
                   3576:         } else {
                   3577:             $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
                   3578:         }
                   3579:         $output .= ' <ul>'.$future.'</ul>';
1.28      raeburn  3580:     }
                   3581:     return $output;
                   3582: }
                   3583: 
1.41.2.2  raeburn  3584: sub acquire_cc_role {
                   3585:     my ($cdom,$cnum,$trolecode,$csec) = @_;
                   3586:     my %coursegroups = &Apache::lonnet::get_active_groups(
                   3587:                         $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
                   3588:     my $cgrps = join(':',keys(%coursegroups));
                   3589:     if ($env{'environment.recentroles'}) {
                   3590:         my %frozen_roles =
                   3591:             &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
                   3592:         &Apache::lonhtmlcommon::store_recent('roles',$trolecode,' ',
                   3593:                                             $frozen_roles{$trolecode});
                   3594:     }
                   3595: 
                   3596:     &Apache::lonnet::appenv({"request.course.id"   => '',
                   3597:                              "request.course.fn"   => '',
                   3598:                              "request.course.uri"  => '',
                   3599:                              "request.course.sec"  => '',
                   3600:                              "request.role"        => 'cm',
                   3601:                              "request.role.adv"    => $env{'user.adv'},
                   3602:                              "request.role.domain" => $env{'user.domain'}});
                   3603: 
                   3604:     &Apache::lonnet::log($env{'user.domain'},
                   3605:                          $env{'user.name'},
                   3606:                          $env{'user.home'},
                   3607:                          "Role ".$trolecode);
                   3608: 
                   3609:     &Apache::lonnet::appenv(
                   3610:                             {'request.role'        => $trolecode,
                   3611:                              'request.role.domain' => $cdom,
                   3612:                              'request.course.sec'  => $csec,
                   3613:                              'request.course.groups' => $cgrps});
                   3614:     my ($furl,$ferr) = &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                   3615:     my $tadv;
                   3616:     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
                   3617:     &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
                   3618:     return;
                   3619: }
                   3620: 
1.41.2.1  raeburn  3621: sub store_crsparms {
                   3622:     my ($cdom,$cnum,$now,$accessstart,$accessend) = @_;
                   3623:     my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
                   3624:     my %crsparms = (
                   3625:                       buttonshide => {
                   3626:                                        value => 'yes',
                   3627:                                        type  => 'string_yesno',
                   3628:                                      },
                   3629:                       opendate    => {
                   3630:                                        value => $accessstart,
                   3631:                                        type  => 'date_start',
                   3632:                                      },
                   3633:                       duedate     => {
                   3634:                                        value => $accessend,
                   3635:                                        type  => 'date_end',
                   3636:                                      },
                   3637:                       problemstatus => {
1.41.2.4  raeburn  3638:                                            value => 'no',
1.41.2.1  raeburn  3639:                                            type  => 'string_problemstatus',
                   3640:                                        },
                   3641:                       maxtries      => {
                   3642:                                            value => '1',
                   3643:                                            type  => 'intpos',
                   3644:                                        },
                   3645:                       discussend    => {
                   3646:                                            value => $now,
                   3647:                                            type  => 'date_end',
                   3648:                                        },
                   3649:                       discusshide   => { 
                   3650:                                            value => 'yes',
                   3651:                                            type  => 'string_yesno',
                   3652:                                        }
                   3653:     );
                   3654:     my %parmresult;
                   3655:     foreach my $item (keys(%crsparms)) {
                   3656:         $parmresult{$item} =
                   3657:             &Apache::lonparmset::storeparm_by_symb($topsymb,
                   3658:                                    '0_'.$item,14,$crsparms{$item}{'value'},
                   3659:                                    $crsparms{$item}{'type'},undef,$cdom);
                   3660:     }
                   3661:     return %parmresult;
                   3662: }
                   3663: 
1.41.2.6  raeburn  3664: sub roster_upload_form {
1.41.2.8  raeburn  3665:     my ($r,$output,$formname,$titletext) = @_;
                   3666:     my $title = &mt('Request Processed');
                   3667:     if ($titletext ne '') {
                   3668:         $title = $titletext;
                   3669:     }
                   3670:     $r->print(<<"ENDJS");
                   3671: <script type="text/javascript">
                   3672: // <![CDATA['
                   3673: 
                   3674: function toggleRosterUpload() {
                   3675:     var willupload;
                   3676:     if (document.$formname.roster.length > 1) {
                   3677:         for (var i=0; i<document.$formname.roster.length; i++) {
                   3678:             if (document.$formname.roster[i].checked) {
                   3679:                 willupload = document.$formname.roster[i].value;
                   3680:             }
                   3681:         }
                   3682:     }
                   3683:     if (willupload == 1) {
                   3684:         document.getElementById('rosterupload').style.display="block";
                   3685:         document.getElementById('norosterupload').style.display="none";
                   3686:     } else {
                   3687:         document.getElementById('rosterupload').style.display="none";
                   3688:         document.getElementById('norosterupload').style.display="block";
                   3689:     }
                   3690:     return;
                   3691: }
                   3692: // ]]
                   3693: </script>
                   3694: 
                   3695: ENDJS
                   3696:     $r->print('<h3>'.$title.'</h3>'.$output.
                   3697:               '<h4>'.&mt('Course roster file upload').'</h4>');
1.41.2.6  raeburn  3698:     $r->print('<p>'.&mt('If you have a text file available containing student e-mail addresses and initial passwords, you may upload it now.').'<br />'.
1.41.2.8  raeburn  3699:     &mt('You may also enroll students later with the [_1]"Enrollment/Activity"[_2] utility in the management toolbar.','<i>','</i>').'</p>'.
                   3700:     &mt('Upload roster file now?').'&nbsp;'.
                   3701:     '<label><input type="radio" name="roster" value="1" '.
                   3702:     'onclick="javascript:toggleRosterUpload()" />'.
                   3703:     &mt('Yes').('&nbsp;'x2).'</label><label>'.
                   3704:     '<input type="radio" name="roster" value="0" checked="checked"'.
                   3705:     'onclick="javascript:toggleRosterUpload()" />'.&mt('No').'</label><br />'.
                   3706:     '<div id="norosterupload"><input type="submit" value="'.&mt('Next').'" name="norostersub" />'.
                   3707:     '<input type="hidden" name="reqaction" value="new" />'.
                   3708:     '<input type="hidden" name="state" value="done" /></div></form>'.
                   3709:     '<div id="rosterupload" style="display: none"><form name="studentform" method="post" enctype="multipart/form-data" '.
1.41.2.6  raeburn  3710:     ' action="/adm/createuser">'."\n");
1.41.2.8  raeburn  3711:     &Apache::lonuserutils::print_first_users_upload_form($r,'course','noheader','requestcrs');
                   3712:     $r->print('<input type="hidden" name="concepttest" value="'.$env{'form.concepttest'}.'" />'.
                   3713:               '</div></form>');
1.41.2.6  raeburn  3714: }
                   3715: 
1.16      raeburn  3716: sub notification_information {
                   3717:     my ($disposition,$req_notifylist,$cnum,$now) = @_;
                   3718:     my %emails = &Apache::loncommon::getemails();
                   3719:     my $address;
                   3720:     if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
                   3721:         $address = $emails{'permanentemail'};
                   3722:         if ($address eq '') {
                   3723:             $address = $emails{'notification'};
                   3724:         }
                   3725:     }
                   3726:     my $output;
                   3727:     if ($disposition eq 'approval') {
                   3728:         $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
                   3729:                    &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
                   3730:         if ($address ne '') {
                   3731:             $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
                   3732:         }
                   3733:         if ($req_notifylist) {
                   3734:             my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                   3735:                                                                      $env{'user.domain'});
                   3736:             my $sender = $env{'user.name'}.':'.$env{'user.domain'};
                   3737:             &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
                   3738:         }
1.17      raeburn  3739:     } elsif ($disposition eq 'pending') {
1.16      raeburn  3740:         $output .= '<div class="LC_info">'.
                   3741: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
                   3742: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
                   3743: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
                   3744:                    '</div>';
1.17      raeburn  3745:     } else {
                   3746:         $output .= '<div class="LC_warning">'.
                   3747:                    &mt('Your request status is: [_1].',$disposition). 
                   3748:                    '</div>'
1.8       raeburn  3749:     }
                   3750:     return $output;
                   3751: }
                   3752: 
                   3753: sub get_processtype {
1.9       raeburn  3754:     my ($dom,$crstype,$inststatuses,$domconfig) = @_;
                   3755:     return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8       raeburn  3756:     my (%userenv,%settings,$val);
1.19      raeburn  3757:     my @options = ('autolimit','validate','approval');
1.8       raeburn  3758:     if ($dom eq $env{'user.domain'}) {
                   3759:         %userenv = 
                   3760:             &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
                   3761:                 'requestcourses.'.$crstype,'inststatus');
                   3762:         if ($userenv{'requestcourses.'.$crstype}) {
                   3763:             $val = $userenv{'requestcourses.'.$crstype};
                   3764:             @{$inststatuses} = ('_custom_');
                   3765:         } else {
                   3766:             my ($task,%alltasks);
1.9       raeburn  3767:             if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
                   3768:                 %settings = %{$domconfig->{'requestcourses'}};
1.8       raeburn  3769:                 if (ref($settings{$crstype}) eq 'HASH') {
1.23      raeburn  3770:                     if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8       raeburn  3771:                         $val = $settings{$crstype}{'_LC_adv'};
                   3772:                         @{$inststatuses} = ('_LC_adv_');
                   3773:                     } else {
                   3774:                         if ($userenv{'inststatus'} ne '') {
                   3775:                             @{$inststatuses} = split(',',$userenv{'inststatus'});
                   3776:                         } else {
1.13      raeburn  3777:                             @{$inststatuses} = ('default');
1.8       raeburn  3778:                         }
                   3779:                         foreach my $status (@{$inststatuses}) {
                   3780:                             if (exists($settings{$crstype}{$status})) {
                   3781:                                 my $value = $settings{$crstype}{$status};
                   3782:                                 next unless ($value); 
                   3783:                                 unless (exists($alltasks{$value})) {
                   3784:                                     if (ref($alltasks{$value}) eq 'ARRAY') {
                   3785:                                         unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
                   3786:                                             push(@{$alltasks{$value}},$status); 
                   3787:                                         }
                   3788:                                     } else {
                   3789:                                         @{$alltasks{$value}} = ($status);
                   3790:                                     }
                   3791:                                 }
                   3792:                             }
                   3793:                         }
                   3794:                         my $maxlimit = 0;
1.13      raeburn  3795:                         
1.8       raeburn  3796:                         foreach my $key (sort(keys(%alltasks))) {
                   3797:                             if ($key =~ /^autolimit=(\d*)$/) {
                   3798:                                 if ($1 eq '') {
                   3799:                                     $val ='autolimit=';
                   3800:                                     last;
                   3801:                                 } elsif ($1 > $maxlimit) {
                   3802:                                     $maxlimit = $1; 
                   3803:                                 }
                   3804:                             }
                   3805:                         }
                   3806:                         if ($maxlimit) {
                   3807:                             $val = 'autolimit='.$maxlimit;
                   3808:                         } else {
                   3809:                             foreach my $option (@options) {
                   3810:                                 if ($alltasks{$option}) {
                   3811:                                     $val = $option;
                   3812:                                     last;  
                   3813:                                 }
                   3814:                             }
                   3815:                         }
                   3816:                     }
                   3817:                 }
                   3818:             }
                   3819:         }
                   3820:     } else {
                   3821:         %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
                   3822:                       $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19      raeburn  3823:         if ($userenv{'reqcrsotherdom.'.$crstype}) {
                   3824:             my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
                   3825:             my $optregex = join('|',@options);
                   3826:             foreach my $item (@doms) {
                   3827:                 my ($extdom,$extopt) = split(':',$item);
                   3828:                 if ($extdom eq $dom) {  
                   3829:                     if ($extopt =~ /^($optregex)(=?\d*)$/) {
                   3830:                         $val = $1.$2;
                   3831:                     }
                   3832:                     last;
                   3833:                 }
1.8       raeburn  3834:             }
                   3835:             @{$inststatuses} = ('_external_');
                   3836:         }
                   3837:     }
                   3838:     return $val;
                   3839: }
                   3840: 
                   3841: sub check_autolimit {
1.10      raeburn  3842:     my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
                   3843:     my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41      raeburn  3844:                        'userroles',['active','future'],['cc','co'],[$dom]);
1.37      raeburn  3845:     my ($types,$typename) = &Apache::loncommon::course_types();
1.10      raeburn  3846:     my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41      raeburn  3847:     my $count = 0;
1.10      raeburn  3848:     foreach my $key (keys(%requests)) {
                   3849:         my ($cdom,$cnum) = split('_',$key);
1.41      raeburn  3850:         if (ref($requests{$key}) eq 'HASH') {
                   3851:             next if ($requests{$key}{'crstype'} ne $crstype);
                   3852:             if (($crstype eq 'community') && 
                   3853:                 (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
                   3854:                 $count ++;
                   3855:             } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
                   3856:                      (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
                   3857:                 $count ++;
1.10      raeburn  3858:             }
                   3859:         }
                   3860:     }
1.41      raeburn  3861:     if ($count < $limit) {
1.10      raeburn  3862:         return 'process';
                   3863:     } else {
                   3864:         if (ref($typename) eq 'HASH') {
1.41      raeburn  3865:             if ($crstype eq 'community') {
                   3866:                 $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
                   3867:                             '<br />'.&mt("Your limit is [_1].",$limit);
                   3868:             } else {
                   3869:                 $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
                   3870:                             '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
                   3871:             }
1.10      raeburn  3872:         }
                   3873:         return 'rejected';
                   3874:     }
1.1       raeburn  3875:     return;
                   3876: }
                   3877: 
1.2       raeburn  3878: sub retrieve_settings {
1.26      raeburn  3879:     my ($dom,$cnum,$udom,$uname) = @_;
                   3880:     if ($udom eq '' || $uname eq '') {
                   3881:         $udom = $env{'user.domain'};
                   3882:         $uname = $env{'user.name'};
                   3883:     }
                   3884:     my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16      raeburn  3885:     if ($result eq 'ok') {
1.26      raeburn  3886:         if (($udom eq $reqinfo{'domain'}) &&  ($uname eq $reqinfo{'owner'})) {
1.16      raeburn  3887:             $env{'form.chome'} = $reqinfo{'coursehome'};
                   3888:             $env{'form.cdescr'} = $reqinfo{'cdescr'};
                   3889:             $env{'form.crstype'} = $reqinfo{'crstype'}; 
                   3890:             &generate_date_items($reqinfo{'accessstart'},'accessstart');
                   3891:             &generate_date_items($reqinfo{'accessend'},'accessend');
                   3892:             if ($reqinfo{'accessend'} == 0) {
                   3893:                 $env{'form.no_end_date'} = 1;
                   3894:             }
                   3895:             if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
                   3896:                 &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
                   3897:                 &generate_date_items($reqinfo{'enrollend'},'enrollend');
                   3898:             }
                   3899:             $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
                   3900:             $env{'form.clonedom'} = $reqinfo{'clonedom'};
                   3901:             $env{'form.datemode'} = $reqinfo{'datemode'};
                   3902:             $env{'form.dateshift'} = $reqinfo{'dateshift'};
                   3903:             if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) { 
                   3904:                  $env{'form.sectotal'} = $reqinfo{'sectotal'};
                   3905:                  $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
                   3906:                  $env{'form.autoadds'} = $reqinfo{'autoadds'};
                   3907:                  $env{'form.autdrops'} = $reqinfo{'autodrops'};
                   3908:                  $env{'form.instcode'} = $reqinfo{'instcode'};
1.24      raeburn  3909:                  my $crscode = { 
                   3910:                                  $cnum => $reqinfo{'instcode'},
                   3911:                                };
                   3912:                  &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16      raeburn  3913:             }
                   3914:             my @currsec;
                   3915:             if (ref($reqinfo{'sections'}) eq 'HASH') {
                   3916:                 foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
                   3917:                     if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24      raeburn  3918:                         my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16      raeburn  3919:                         $env{'form.secnum_'.$i} = $sec;
1.24      raeburn  3920:                         $env{'form.sec_'.$i} = '1';
1.16      raeburn  3921:                         if (!grep(/^\Q$sec\E$/,@currsec)) {
                   3922:                             push(@currsec,$sec);
                   3923:                         }
                   3924:                         $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
                   3925:                     }
                   3926:                 }
                   3927:             }
1.24      raeburn  3928:             if (ref($reqinfo{'crosslists'}) eq 'HASH') {
                   3929:                 foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
                   3930:                     if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
                   3931:                         $env{'form.crosslist_'.$i} = '1';
                   3932:                         $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
                   3933:                         $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
                   3934:                         if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
                   3935:                             my $key = $cnum.$i; 
                   3936:                             my $crscode = {
                   3937:                                               $key => $reqinfo{'crosslists'}{$i}{'instcode'},
                   3938:                                           };
                   3939:                             &extract_instcode($dom,'crosslist',$crscode,$key,$i);
                   3940:                         }
1.16      raeburn  3941:                     }
                   3942:                 }
                   3943:             }
                   3944:             if (ref($reqinfo{'personnel'}) eq 'HASH') {
                   3945:                 my $i = 0;
                   3946:                 foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
                   3947:                     my ($uname,$udom) = split(':',$user);
                   3948:                     if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
                   3949:                         if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
                   3950:                             foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
                   3951:                                 $env{'form.person_'.$i.'_role'} = $role;
                   3952:                                 $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
                   3953:                                 $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
                   3954:                                 $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
                   3955:                                 $env{'form.person_'.$i.'_uname'} = $uname;
                   3956:                                 $env{'form.person_'.$i.'_dom'} = $udom;
                   3957:                                 if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
                   3958:                                     if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
                   3959:                                         my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
                   3960:                                         my @newsecs;
                   3961:                                         if (@usecs > 0) {
                   3962:                                             foreach my $sec (@usecs) {
                   3963:                                                 if (grep(/^\Q$sec\E/,@currsec)) {
                   3964:                                                     $env{'form.person_'.$i.'_sec'} = $sec;
                   3965:                                                 } else {
1.20      raeburn  3966:                                                     push(@newsecs,$sec);
1.16      raeburn  3967:                                                 }
                   3968:                                             }
                   3969:                                         }
                   3970:                                         if (@newsecs > 0) {
                   3971:                                             $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs); 
                   3972:                                         }
                   3973:                                     }
                   3974:                                 }
                   3975:                                 $i ++;
                   3976:                             }
                   3977:                         }
                   3978:                     }
                   3979:                 }
                   3980:                 $env{'form.persontotal'} = $i;
                   3981:             }
                   3982:         }
                   3983:     }
                   3984:     return $result;
                   3985: }
                   3986: 
                   3987: sub get_request_settings {
1.26      raeburn  3988:     my ($dom,$cnum,$udom,$uname) = @_;
1.16      raeburn  3989:     my $requestkey = $dom.'_'.$cnum;
                   3990:     my ($result,%reqinfo);
                   3991:     if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26      raeburn  3992:         my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16      raeburn  3993:         my $disposition = $history{'disposition'};
                   3994:         if (($disposition eq 'approval') || ($disposition eq 'pending')) { 
                   3995:             if (ref($history{'details'}) eq 'HASH') {
                   3996:                 %reqinfo = %{$history{'details'}};
                   3997:                 $result = 'ok';
                   3998:             } else {
                   3999:                 $result = 'nothash';
                   4000:             }
                   4001:         } else {
                   4002:             $result = 'notqueued';
                   4003:         }
                   4004:     } else {
                   4005:         $result = 'invalid';
                   4006:     }
                   4007:     return ($result,%reqinfo);
                   4008: }
1.2       raeburn  4009: 
1.16      raeburn  4010: sub extract_instcode {
1.24      raeburn  4011:     my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16      raeburn  4012:     my (%codes,@codetitles,%cat_titles,%cat_order);
1.24      raeburn  4013:     if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
                   4014:                                               \@codetitles,\%cat_titles,
                   4015:                                               \%cat_order) eq 'ok') {
                   4016:         if (ref($codes{$crskey}) eq 'HASH') {
1.16      raeburn  4017:             if (@codetitles > 0) {
                   4018:                 my $sel = $element;
                   4019:                 if ($element eq 'crosslist') {
                   4020:                     $sel .= '_'.$counter;
                   4021:                 }
                   4022:                 foreach my $title (@codetitles) {
1.24      raeburn  4023:                     $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16      raeburn  4024:                 }
                   4025:             }
                   4026:         }
                   4027:     }
                   4028:     return;
1.2       raeburn  4029: }
                   4030: 
1.16      raeburn  4031: sub generate_date_items {
                   4032:     my ($currentval,$item) = @_;
                   4033:     if ($currentval =~ /\d+/) {
                   4034:         my ($tzname,$sec,$min,$hour,$mday,$month,$year) = 
                   4035:             &Apache::lonhtmlcommon::get_timedates($currentval);
                   4036:         $env{'form.'.$item.'_day'} = $mday;
                   4037:         $env{'form.'.$item.'_month'} = $month+1;
                   4038:         $env{'form.'.$item.'_year'} = $year;
                   4039:     }
                   4040:     return;
1.2       raeburn  4041: }
                   4042: 
1.41.2.6  raeburn  4043: sub show_cloneable {
                   4044:     my $showclone;
                   4045:     if (&Apache::loncommon::needs_gci_custom()) {
                   4046:         my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
                   4047:         my $numcourses = scalar(keys(%courses));
                   4048:         return $numcourses;
                   4049:     } else {
                   4050:         return 1;
                   4051:     }
                   4052: }
                   4053: 
1.1       raeburn  4054: 1;
                   4055: 

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