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

1.1       raeburn     1: # The LearningOnline Network
                      2: # Request a course
                      3: #
1.77    ! raeburn     4: # $Id: lonrequestcourse.pm,v 1.76 2014/01/08 17:18:12 bisitz 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 check_autolimit()
                     98: 
                     99: =item retrieve_settings()
                    100: 
                    101: =item get_request_settings()
                    102: 
1.27      raeburn   103: =item extract_instcode() 
                    104: 
                    105: =item generate_date_items()
                    106: 
1.1       raeburn   107: =back
                    108: 
                    109: =cut
                    110: 
                    111: package Apache::lonrequestcourse;
                    112: 
                    113: use strict;
                    114: use Apache::Constants qw(:common :http);
                    115: use Apache::lonnet;
                    116: use Apache::loncommon;
                    117: use Apache::lonlocal;
1.8       raeburn   118: use Apache::loncoursequeueadmin;
1.30      raeburn   119: use Apache::lonuserutils;
1.4       raeburn   120: use LONCAPA qw(:DEFAULT :match);
1.1       raeburn   121: 
                    122: sub handler {
                    123:     my ($r) = @_;
1.20      raeburn   124:     &Apache::loncommon::content_type($r,'text/html');
                    125:     $r->send_http_header;
1.1       raeburn   126:     if ($r->header_only) {
                    127:         return OK;
                    128:     }
                    129: 
1.27      raeburn   130:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.73      raeburn   131:         ['action','showdom','cnum','state','crstype','queue','tabs']);
1.2       raeburn   132:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    133:     my $dom = &get_course_dom();
1.1       raeburn   134:     my $action = $env{'form.action'};
                    135:     my $state = $env{'form.state'};
1.27      raeburn   136:     my (%states,%stored);
1.72      raeburn   137:     my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits,%can_request,
                    138:         %request_domains,@incdoms);
1.66      raeburn   139:     my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.69      raeburn   140:     if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) {
1.66      raeburn   141:         $showcredits = 1;
                    142:     }
1.27      raeburn   143: 
1.72      raeburn   144:     my $canreq =
                    145:         &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
                    146: 
                    147:     foreach my $item (keys(%request_domains)) {
                    148:         if (ref($request_domains{$item}) eq 'ARRAY') {
                    149:             foreach my $possdom (@{$request_domains{$item}}) {
                    150:                 unless(grep(/^\Q$possdom\E$/,@incdoms)) {
                    151:                     push(@incdoms,$possdom);
                    152:                 }
                    153:             }
                    154:         }
                    155:     }
                    156: 
                    157:     if ($canreq) {
1.73      raeburn   158:         if (($env{'form.crstype'} eq 'textbook') || 
                    159:             (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
1.72      raeburn   160:             my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
                    161:             if ($action eq 'log') {
1.73      raeburn   162:                 my $usetabs;
                    163:                 if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
                    164:                     $usetabs = 1;
                    165:                 } elsif ($env{'form.tabs'} eq 'on') {
                    166:                     $usetabs = 1;
                    167:                 }
1.72      raeburn   168:                 &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
                    169:                 my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.73      raeburn   170:                 &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs);
1.72      raeburn   171:             } elsif ($action eq 'process') {
1.73      raeburn   172:                 if ($can_request{'textbook'}) {
                    173:                     &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request);
                    174:                 } else {
                    175:                     &textbook_request_disabled($r,$dom,\%can_request);
                    176:                 }
1.72      raeburn   177:             } else {
1.73      raeburn   178:                 if ($can_request{'textbook'}) {
                    179:                     &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request);
                    180:                 } else {
                    181:                     &textbook_request_disabled($r,$dom,\%can_request);
                    182:                 }
1.72      raeburn   183:             }
                    184:             return OK;
                    185:         }
                    186:     }
                    187: 
1.27      raeburn   188:     $states{'display'} = ['details'];
                    189:     $states{'view'} = ['pick_request','details','cancel','removal'];
1.48      raeburn   190:     $states{'log'} = ['display'];
1.27      raeburn   191:     $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
                    192: 
                    193:     if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
                    194:         unless ($env{'form.state'} eq 'crstype') {
                    195:             unshift(@{$states{'new'}},'codepick');
                    196:         }
                    197:     }
                    198: 
1.65      raeburn   199:     if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
                    200:         if (ref($states{$action}) eq 'ARRAY') {
                    201:             push(@{$states{$action}},'reqauthor');
                    202:         }
                    203:     }
                    204: 
1.27      raeburn   205:     foreach my $key (keys(%states)) {
                    206:         if (ref($states{$key}) eq 'ARRAY') {
                    207:             unshift (@{$states{$key}},'crstype');
                    208:         }
                    209:     }
                    210: 
                    211:     my @invalidcrosslist;
                    212:     my %trail = (
1.73      raeburn   213:                  crstype       => 'Pick Action',
1.27      raeburn   214:                  codepick      => 'Category',
                    215:                  courseinfo    => 'Description',
                    216:                  enrollment    => 'Access Dates',
                    217:                  personnel     => 'Personnel',
                    218:                  review        => 'Review',
                    219:                  process       => 'Result',
1.65      raeburn   220:                  reqauthor     => 'Authoring Space Result',
1.27      raeburn   221:                  pick_request  => 'Display Summary',
                    222:                  details       => 'Request Details',
                    223:                  cancel        => 'Cancel Request',
                    224:                  removal       => 'Outcome',
1.48      raeburn   225:                  display       => 'Request Logs',
1.27      raeburn   226:                 );
                    227: 
                    228:     if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
                    229:         $trail{'enrollment'} = 'Enrollment';
                    230:     }
                    231: 
1.66      raeburn   232:     my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27      raeburn   233:         &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26      raeburn   234:     if ($action eq 'display') {
                    235:         if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
                    236:             if ($env{'form.cnum'} ne '') {
                    237:                 my $cnum = $env{'form.cnum'};
1.49      raeburn   238:                 my $queue = $env{'form.queue'};
                    239:                 my $reqkey = $cnum.'_'.$queue;
1.26      raeburn   240:                 my $namespace = 'courserequestqueue';
                    241:                 my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
                    242:                 my %queued =
                    243:                     &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
                    244:                 if (ref($queued{$reqkey}) eq 'HASH') {
                    245:                     $uname = $queued{$reqkey}{'ownername'};
                    246:                     $udom  = $queued{$reqkey}{'ownerdom'};
                    247:                     if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
                    248:                         $result = &retrieve_settings($dom,$cnum,$udom,$uname);
                    249:                     } else {
1.40      raeburn   250:                         if ($env{'form.crstype'} eq 'community') {
                    251:                             $warning = &mt('Invalid username or domain for community requestor');
                    252:                         } else {
                    253:                             $warning = &mt('Invalid username or domain for course requestor');
                    254:                         }
1.26      raeburn   255:                     }
                    256:                 } else {
1.40      raeburn   257:                     if ($env{'form.crstype'} eq 'community') {
                    258:                         $warning = &mt('No information was found for this community request.');
                    259:                     } else {
                    260:                         $warning = &mt('No information was found for this course request.');
                    261:                     }
1.26      raeburn   262:                 }
                    263:             } else {
                    264:                 $warning = &mt('No course request ID provided.');
                    265:             }
                    266:         } else {
1.40      raeburn   267:             if ($env{'form.crstype'} eq 'any') {
                    268:                $warning = &mt('You do not have rights to view course or community request information.');
                    269:             } elsif ($env{'form.crstype'} eq 'community') {
                    270:                 $warning = &mt('You do not have rights to view community request information.');
                    271:             } else {
                    272:                 $warning = &mt('You do not have rights to view course request information.');
                    273:             }
1.26      raeburn   274:         }
                    275:     } elsif ((defined($state)) && (defined($action))) {
1.16      raeburn   276:         if (($action eq 'view') && ($state eq 'details')) {
                    277:             if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
                    278:                 my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2       raeburn   279:             }
1.27      raeburn   280:         } elsif ($env{'form.crstype'} eq 'official') {
                    281:             if (&Apache::lonnet::auto_run('',$dom)) {
                    282:                 if (($action eq 'new') && (($state eq 'enrollment') || 
                    283:                     ($state eq 'personnel'))) {
                    284:                     my $checkcrosslist = 0;
                    285:                     for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    286:                         if ($env{'form.crosslist_'.$i}) {
                    287:                             $checkcrosslist ++;
                    288:                         }
                    289:                     }
                    290:                     if ($checkcrosslist) {
                    291:                         my %codechk;
                    292:                         my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
                    293:                         &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
                    294:                                                                  \%cat_titles,
                    295:                                                                  \%cat_order,
                    296:                                                                  \@code_order);
                    297:                         my $numtitles = scalar(@codetitles);
                    298:                         if ($numtitles) {
                    299:                             for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    300:                                 if ($env{'form.crosslist_'.$i}) {
                    301:                                     my $codecheck;
                    302:                                     my $crosslistcode = '';
                    303:                                     foreach my $item (@code_order) {
                    304:                                         $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item}; 
                    305:                                     }
                    306:                                     if ($crosslistcode ne '') { 
1.36      raeburn   307:                                          ($codechk{$i}, my $rest) = 
1.27      raeburn   308:                                             &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
                    309:                                     }
                    310:                                     unless ($codechk{$i} eq 'valid') {
                    311:                                         $env{'form.crosslist_'.$i} = '';
                    312:                                         push(@invalidcrosslist,$crosslistcode);
                    313:                                     } 
                    314:                                 }
                    315:                             }
                    316:                         }
                    317:                     }
                    318:                 }
                    319:             }
1.2       raeburn   320:         }
1.66      raeburn   321:         (my $elements,$instcredits) = &form_elements($dom,$showcredits);
1.2       raeburn   322:         my $elementsref = {};
1.66      raeburn   323:         if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) {
                    324:             if (ref($elements->{$action}{$state}) eq 'HASH') {
                    325:                 $elementsref = $elements->{$action}{$state};
1.2       raeburn   326:             }
                    327:         }
1.16      raeburn   328:         if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
                    329:             $env{'form.clonedom'} = $dom;
                    330:         }
1.30      raeburn   331:         if ($state eq 'crstype') {
                    332:             $jscript = &mainmenu_javascript();
                    333:         } else {
                    334:             $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.45      raeburn   335:             if ($state eq 'courseinfo') {
                    336:                 $jscript .= &cloning_javascript();
                    337:             }
1.30      raeburn   338:         }
1.2       raeburn   339:     }
                    340: 
                    341:     if ($state eq 'personnel') {
                    342:         $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
                    343:     }
                    344: 
                    345:     my $loaditems = &onload_action($action,$state);
                    346: 
1.1       raeburn   347:     if ($action eq 'new') {
                    348:         if ($canreq) {
                    349:             if ($state eq 'crstype') {
1.3       raeburn   350:                 &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.72      raeburn   351:                                  $crumb,\@incdoms);
1.1       raeburn   352:             } else {
1.27      raeburn   353:                 &request_administration($r,$action,$state,$page,\%states,$dom,
                    354:                                         $jscript,$loaditems,$crumb,$newinstcode,
1.36      raeburn   355:                                         $codechk,$checkedcode,$description,
1.66      raeburn   356:                                         $showcredits,$instcredits,\@invalidcrosslist);
1.1       raeburn   357:             }
                    358:         } else {
1.40      raeburn   359:             $r->print(&header('Course/Community Requests').$crumb.
1.1       raeburn   360:                       '<div class="LC_warning">'.
1.40      raeburn   361:                       &mt('You do not have privileges to request creation of courses or communities.').
1.2       raeburn   362:                       '</div>'.&Apache::loncommon::end_page());
1.1       raeburn   363:         }
                    364:     } elsif ($action eq 'view') {
1.10      raeburn   365:         if ($state eq 'crstype') {
1.72      raeburn   366:             &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\@incdoms);
1.26      raeburn   367:         } else {
                    368:             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66      raeburn   369:                                     $loaditems,$crumb,'','','','',$showcredits);
1.26      raeburn   370:         }
                    371:     } elsif ($action eq 'display') {
                    372:         if ($warning ne '') {
                    373:             my $args = { only_body => 1 };
1.49      raeburn   374:             $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
1.40      raeburn   375:                       '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26      raeburn   376:                       '<div class="LC_warning">'.$warning.'</div>'.
                    377:                       &close_popup_form());
1.11      raeburn   378:         } else {
1.26      raeburn   379:             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66      raeburn   380:                                     $loaditems,$crumb,'','','','',$showcredits,'','',
                    381:                                     $uname,$udom);
1.10      raeburn   382:         }
1.1       raeburn   383:     } elsif ($action eq 'log') {
1.48      raeburn   384:         if ($state eq 'crstype') {
1.72      raeburn   385:             &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.48      raeburn   386:         } else {
                    387:             $jscript .= <<ENDJS;
                    388: 
                    389: function backPage(formname,prevstate) {
                    390:     formname.state.value = prevstate;
                    391:     formname.submit();
                    392: }
                    393: 
                    394: function setPage(formname) {
                    395:     formname.page.value = '1';
                    396:     return;
                    397: }
                    398: 
                    399: ENDJS
1.73      raeburn   400:             &print_request_logs($r,$dom,$jscript,$loaditems,$crumb,\%can_request);
1.48      raeburn   401:         }
1.1       raeburn   402:     } else {
1.72      raeburn   403:         &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.1       raeburn   404:     }
                    405:     return OK;
                    406: }
                    407: 
1.30      raeburn   408: sub mainmenu_javascript {
                    409:     return <<"END";
                    410: function setType(courseForm) {
                    411:     for (var i=0; i<courseForm.crstype.length; i++) {
                    412:         if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
                    413:             courseForm.crstype.options[i].selected = true;
                    414:         } else {
                    415:             courseForm.crstype.options[i].selected = false;
                    416:         }
                    417:     }
                    418: }
                    419: 
                    420: function setAction(courseForm) {
                    421:     for (var i=0; i<courseForm.action.length; i++) {
                    422:         if (courseForm.action.options[i].value == "$env{'form.action'}") {
                    423:             courseForm.action.options[i].selected = true;
                    424:         } else {
                    425:             courseForm.action.options[i].selected = false;
                    426:         }
                    427:     }
                    428: }
                    429: END
                    430: }
                    431: 
1.45      raeburn   432: sub cloning_javascript {
                    433:     return <<"END";
                    434: function setCloneDisplay(courseForm) {
                    435:     if (courseForm.cloning.length > 1) {    
                    436:         for (var i=0; i<courseForm.cloning.length; i++) {
                    437:             if (courseForm.cloning[i].checked) {
                    438:                 if (courseForm.cloning[i].value == 1) {
                    439:                     document.getElementById('cloneoptions').style.display="block";;
                    440:                 }
                    441:             }
                    442:         }
                    443:     }
                    444: }
                    445: END
                    446: }
                    447: 
1.27      raeburn   448: sub get_breadcrumbs {
                    449:     my ($dom,$action,$state,$states,$trail) = @_;
1.36      raeburn   450:     my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27      raeburn   451:     my $page = 0;
                    452:     if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
                    453:         if (defined($action)) {
                    454:             my $done = 0;
                    455:             my $i=0;
                    456:             if (ref($states->{$action}) eq 'ARRAY') {
                    457:                 while ($i<@{$states->{$action}} && !$done) {
                    458:                     if ($states->{$action}[$i] eq $$state) {
                    459:                         $page = $i;
                    460:                         $done = 1;
                    461:                     }
                    462:                     $i++;
                    463:                 }
                    464:             }
                    465:             if ($env{'form.crstype'} eq 'official') {
                    466:                 if ($page > 1) {
                    467:                     if ($states->{$action}[$page-1] eq 'codepick') {
                    468:                         if ($env{'form.instcode'} eq '') {
                    469:                             ($newinstcode,$numtitles) = &get_instcode($dom);
                    470:                             if ($numtitles) {
                    471:                                 if ($newinstcode eq '') {
                    472:                                     $$state = 'codepick';
                    473:                                     $page --;
                    474:                                 } else {
1.36      raeburn   475:                                     ($codechk,$description) = 
1.27      raeburn   476:                                         &Apache::lonnet::auto_validate_instcode('',
                    477:                                             $dom,$newinstcode);
                    478:                                     if ($codechk ne 'valid') {
                    479:                                         $$state = 'codepick';
                    480:                                         $page --;
                    481:                                     }
                    482:                                     $checkedcode = 1;
                    483:                                 }
                    484:                             }
                    485:                         }
                    486:                     }
                    487:                 }
                    488:             }
                    489:             for (my $i=0; $i<@{$states->{$action}}; $i++) {
                    490:                 if ($$state eq $states->{$action}[$i]) {
                    491:                     &Apache::lonhtmlcommon::add_breadcrumb(
                    492:                        {text=>"$trail->{$$state}"});
1.40      raeburn   493:                     $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27      raeburn   494:                     last;
                    495:                 } else {
1.65      raeburn   496:                     if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
1.27      raeburn   497:                         &Apache::lonhtmlcommon::add_breadcrumb(
                    498:                             { href => '/adm/requestcourse',
                    499:                               text => "$trail->{$states->{$action}[$i]}",
                    500:                             }
                    501:                         );
                    502:                     } else {
                    503:                         &Apache::lonhtmlcommon::add_breadcrumb(
                    504:      { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
                    505:        text => "$trail->{$states->{$action}[$i]}", }
                    506:                        );
                    507:                    }
                    508:                }
                    509:            }
                    510:         } else {
                    511:             &Apache::lonhtmlcommon::add_breadcrumb(
                    512:                     {text=>'Pick Action'});
1.40      raeburn   513:             $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27      raeburn   514:         }
                    515:     } else {
                    516:         &Apache::lonhtmlcommon::add_breadcrumb(
                    517:                 {text=>'Pick Action'});
1.40      raeburn   518:         $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27      raeburn   519:     }
1.36      raeburn   520:     return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27      raeburn   521: }
                    522: 
1.2       raeburn   523: sub header {
1.26      raeburn   524:     my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2       raeburn   525:     if ($jscript) {
1.6       raeburn   526:         $jscript = '<script type="text/javascript">'."\n".
                    527:                    '// <![CDATA['."\n".
                    528:                    $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2       raeburn   529:     }
                    530:     if ($loaditems) {
1.26      raeburn   531:         if (ref($args) eq 'HASH') {
                    532:             my %loadhash = (
                    533:                              'add_entries' => $loaditems,
                    534:                            );
                    535:             my %arghash = (%loadhash,%{$args});
                    536:             $args = \%arghash;                  
                    537:         } else {
                    538:             $args = {'add_entries' => $loaditems,};
                    539:         }
1.3       raeburn   540:     }
1.26      raeburn   541:     return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2       raeburn   542: }
                    543: 
                    544: sub form_elements {
1.66      raeburn   545:     my ($dom,$showcredits) = @_;
                    546:     my $instcredits;
1.2       raeburn   547:     my %elements =
                    548:     (
                    549:         new => {
                    550:             crstype => {
                    551:                 crstype => 'selectbox',
                    552:                 action  => 'selectbox',
1.16      raeburn   553:                 origcnum => 'hidden', 
1.2       raeburn   554:             },
                    555:             courseinfo => {
                    556:                 cdescr           => 'text',
1.45      raeburn   557:                 cloning          => 'radio', 
1.13      raeburn   558:                 clonecrs         => 'text',
                    559:                 clonedom         => 'selectbox',
1.2       raeburn   560:                 datemode         => 'radio',
                    561:                 dateshift        => 'text',
                    562:             },
                    563:             enrollment  => {
1.13      raeburn   564:                 accessstart_month  => 'selectbox',
                    565:                 accessstart_hour   => 'selectbox',
                    566:                 accessend_month    => 'selectbox',
                    567:                 accessend_hour     => 'selectbox',
                    568:                 accessstart_day    => 'text',
                    569:                 accessstart_year   => 'text',
                    570:                 accessstart_minute => 'text',
                    571:                 accessstart_second => 'text',
                    572:                 accessend_day      => 'text',
                    573:                 accessend_year     => 'text',
                    574:                 accessend_minute   => 'text',
                    575:                 accessend_second   => 'text',
1.2       raeburn   576:                 no_end_date      => 'checkbox',
                    577:             },
                    578:             personnel => {
                    579:                 addperson   => 'checkbox', 
                    580:             },
1.13      raeburn   581:             review => {
                    582:                 cnum => 'hidden',
                    583:             },
1.2       raeburn   584:          },
                    585:          view => {
                    586:             crstype => {
                    587:                 crstype => 'selectbox',
                    588:                 action  => 'selectbox',
                    589:             },
                    590:          },
                    591:     );
1.13      raeburn   592:     my %servers = &Apache::lonnet::get_servers($dom,'library');
                    593:     my $numlib = keys(%servers);
                    594:     if ($numlib > 1) {
                    595:         $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
                    596:     } else {
                    597:         $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
                    598:     }
1.2       raeburn   599:     my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
                    600:     &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                    601:                                              \%cat_order,\@code_order);
                    602:     my $numtitles = scalar(@codetitles);
                    603:     if ($numtitles) {
                    604:         my %extras;
                    605:         $lastitem = pop(@codetitles);
                    606:         $extras{'instcode_'.$lastitem} = 'text'; 
                    607:         foreach my $item (@codetitles) {
                    608:             $extras{'instcode_'.$item} = 'selectbox';   
                    609:         }
                    610:         $elements{'new'}{'codepick'} = \%extras;
                    611:     }
                    612:     if (&Apache::lonnet::auto_run('',$dom)) {
                    613:         my %extras = (
1.13      raeburn   614:                        enrollstart_month  => 'selectbox',
                    615:                        enrollstart_hour   => 'selectbox',
                    616:                        enrollend_month    => 'selectbox',
                    617:                        enrollend_hour     => 'selectbox',
                    618:                        enrollstart_day    => 'text',
                    619:                        enrollstart_year   => 'text',
                    620:                        enrollstart_minute => 'text',
                    621:                        enrollstart_second => 'text',
                    622:                        enrollend_day      => 'text',
                    623:                        enrollend_year     => 'text',
                    624:                        enrollend_minute   => 'text',
                    625:                        enrollend_second   => 'text',
1.2       raeburn   626:                        addcrosslist       => 'checkbox',
                    627:                        autoadds           => 'radio',
                    628:                        autodrops          => 'radio',
1.61      raeburn   629:         );
                    630:         my ($instcode,$titlescount) = &get_instcode($dom);
                    631:         if ($instcode) {
                    632:             my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
                    633:             if (@sections) {
                    634:                 $extras{'sectotal'} = 'hidden';
                    635:                 if ($env{'form.sectotal'} > 0) {
                    636:                     for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                    637:                         $extras{'sec_'.$i} = 'radio';
                    638:                         $extras{'secnum_'.$i} = 'text';
                    639:                         $extras{'loncapasec_'.$i} = 'text';
                    640:                     }
                    641:                 }
                    642:             } else {
                    643:                 $extras{'addsection'} = 'checkbox';
                    644:                 my $sectotal = $env{'form.sectotal'};
                    645:                 if ($env{'form.addsection'}) {
                    646:                     $sectotal ++;
                    647:                 }
                    648:                 for (my $i=0; $i<$sectotal; $i++) {
                    649:                     $extras{'sec_'.$i} = 'checkbox';
                    650:                     $extras{'secnum_'.$i} = 'text',
                    651:                     $extras{'loncapasec_'.$i} = 'text',
                    652:                 }
1.2       raeburn   653:             }
1.66      raeburn   654:             (my $outcome,my $desc,$instcredits) = 
                    655:                 &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode);
                    656:             if ($showcredits && $instcredits eq '') {
                    657:                 $extras{'coursecredits'} = 'text';
                    658:             }
1.69      raeburn   659:         } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66      raeburn   660:             if ($showcredits) {
                    661:                 $extras{'coursecredits'} = 'text';
                    662:             }
1.2       raeburn   663:         }
                    664:         my $crosslisttotal = $env{'form.crosslisttotal'};
1.16      raeburn   665:         if ($env{'form.addcrosslist'}) {
                    666:             $crosslisttotal ++;
                    667:         }
1.24      raeburn   668:         if (!$crosslisttotal) {
1.2       raeburn   669:             $crosslisttotal = 1;
                    670:         }
1.24      raeburn   671:         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                    672:             if ($numtitles) {
                    673:                 $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
                    674:             }
                    675:             if (@codetitles > 0) {
                    676:                 foreach my $item (@codetitles) {
                    677:                     $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2       raeburn   678:                 }
                    679:             }
1.24      raeburn   680:             $extras{'crosslist_'.$i} = 'checkbox';
                    681:             $extras{'crosslist_'.$i.'_instsec'} = 'text',
                    682:             $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2       raeburn   683:         }
                    684:         my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
                    685:         %{$elements{'new'}{'enrollment'}} = %mergedhash;
                    686:     }
                    687:     my %people;
                    688:     my $persontotal = $env{'form.persontotal'};
1.16      raeburn   689:     if ($env{'form.addperson'}) {
                    690:         $persontotal ++;
                    691:     }
                    692:     if ((!defined($persontotal)) || (!$persontotal)) {
1.2       raeburn   693:         $persontotal = 1;
                    694:     }
                    695:     for (my $i=0; $i<$persontotal; $i++) {
1.13      raeburn   696:         $people{'person_'.$i.'_uname'}     = 'text',
                    697:         $people{'person_'.$i.'_dom'}       = 'selectbox',
                    698:         $people{'person_'.$i.'_hidedom'}   = 'hidden',
                    699:         $people{'person_'.$i.'_firstname'} = 'text',
                    700:         $people{'person_'.$i.'_lastname'}  = 'text',
                    701:         $people{'person_'.$i.'_emailaddr'} = 'text',
                    702:         $people{'person_'.$i.'_role'}      = 'selectbox',
                    703:         $people{'person_'.$i.'_sec'}       = 'selectbox',
                    704:         $people{'person_'.$i.'_newsec'}    = 'text',
1.2       raeburn   705:     }
                    706:     my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
                    707:     %{$elements{'new'}{'personnel'}} = %personnelhash;
1.66      raeburn   708:     return (\%elements,$instcredits);;
1.2       raeburn   709: }
                    710: 
                    711: sub onload_action {
                    712:     my ($action,$state) = @_;
                    713:     my %loaditems;
                    714:     if (($action eq 'new') || ($action eq 'view')) {
1.30      raeburn   715:         if ($state eq 'crstype') {
                    716:             $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
                    717:         } else {
1.45      raeburn   718:             $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
                    719:         }
                    720:         if ($state eq 'courseinfo') {
                    721:             $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
1.30      raeburn   722:         }
1.2       raeburn   723:     }
                    724:     return \%loaditems;
                    725: }
                    726: 
1.1       raeburn   727: sub print_main_menu {
1.72      raeburn   728:     my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$incdoms) = @_;
1.37      raeburn   729:     my ($types,$typename) = &Apache::loncommon::course_types();
1.52      bisitz    730:     my $onchange = 'this.form.submit()';
1.2       raeburn   731:     my $nextstate_setter = "\n";
                    732:     if (ref($states) eq 'HASH') {
                    733:         foreach my $key (keys(%{$states})) {
                    734:             if (ref($states->{$key}) eq 'ARRAY') {
                    735:                 $nextstate_setter .= 
                    736: "             if (actionchoice == '$key') {
                    737:                   nextstate = '".$states->{$key}[1]."';
                    738:              }
                    739: ";
                    740:             }
                    741:         }
                    742:     }
1.1       raeburn   743: 
1.2       raeburn   744:     my $js = <<"END";
1.1       raeburn   745: 
1.2       raeburn   746: function nextPage(formname) {
1.27      raeburn   747:     var crschoice = document.mainmenu_coursetype.crstype.value;
                    748:     var actionchoice = document.mainmenu_action.action.value;
1.2       raeburn   749:     if (check_can_request(crschoice,actionchoice) == true) {
                    750:         if ((actionchoice == 'new') && (crschoice == 'official')) {
                    751:             nextstate = 'codepick';
                    752:         } else {
                    753: $nextstate_setter 
1.27      raeburn   754:         }
                    755:         formname.crstype.value = crschoice;
                    756:         formname.action.value = actionchoice; 
1.1       raeburn   757:         formname.state.value= nextstate;
                    758:         formname.submit();
                    759:     }
                    760:     return;
                    761: }
                    762: 
1.2       raeburn   763: function check_can_request(crschoice,actionchoice) {
1.1       raeburn   764:     var official = '';
                    765:     var unofficial = '';
1.69      raeburn   766:     var community = '';
                    767:     var textbook = '';
1.1       raeburn   768: END
1.39      raeburn   769:     if (ref($can_request) eq 'HASH') {
                    770:         foreach my $item (keys(%{$can_request})) {
                    771:                 $js .= " 
1.1       raeburn   772:         $item = 1;
                    773: ";
1.39      raeburn   774:         }
1.1       raeburn   775:     }
                    776:     my %lt = &Apache::lonlocal::texthash(
                    777:         official => 'You are not permitted to request creation of an official course in this domain.',
                    778:         unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
1.69      raeburn   779:         community => 'You are not permitted to request creation of a community in this domain.',
                    780:         textbook => 'You are not permitted to request creation of a textbook course in this domain',
1.67      raeburn   781:         all => 'You must choose a specific course type when making a new course request.',
                    782:         allt => '"All types" is not allowed.',
1.1       raeburn   783:     ); 
                    784:     $js .= <<END;
                    785:     if (crschoice == 'official') {
                    786:         if (official != 1) {
                    787:             alert("$lt{'official'}");
                    788:             return false;
                    789:         }
                    790:     } else {
                    791:         if (crschoice == 'unofficial') {
                    792:             if (unofficial != 1) {
                    793:                 alert("$lt{'unofficial'}");
                    794:                 return false;
                    795:             }
                    796:         } else {
                    797:             if (crschoice == 'community') {
                    798:                 if (community != 1) {
                    799:                     alert("$lt{'community'}");
                    800:                     return false;
                    801:                 }
                    802:             } else {
1.69      raeburn   803:                 if (crschoice == 'textbook') {
                    804:                     if (textbook != 1) {
                    805:                         alert("$lt{'community'}");
                    806:                         return false;
                    807:                     }
                    808:                 } else {
                    809:                     if (actionchoice == 'new') {
                    810:                         alert('$lt{'all'}'+'\\n'+'$lt{'allt'}');
                    811:                         return false;
                    812:                     }
                    813:                 }
1.1       raeburn   814:             }
                    815:         }
                    816:     }
                    817:     return true;
                    818: }
                    819: END
1.75      raeburn   820:     my ($pagetitle,$pageinfo,$domaintitle,$earlyout);
1.39      raeburn   821:     if (ref($can_request) eq 'HASH') {
1.69      raeburn   822:         if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) {
1.39      raeburn   823:             if ($can_request->{'community'}) {
                    824:                 $pagetitle = 'Course/Community Requests';
                    825:                 $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
                    826:                 $domaintitle = &mt('Course/Community Domain');
                    827:             } else {
                    828:                 $pagetitle = 'Course Requests';
                    829:                 $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
                    830:                 $domaintitle = &mt('Course Domain');
                    831:             }
                    832:         } elsif ($can_request->{'community'}) {
1.40      raeburn   833:             $pagetitle = 'Community Requests';
                    834:             $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39      raeburn   835:             $domaintitle = &mt('Community Domain');
1.75      raeburn   836:         } elsif ((ref($incdoms) eq 'ARRAY') && ((@{$incdoms} > 1) ||
                    837:                  ((@{$incdoms} == 1) && ($incdoms->[0] ne $dom)))) {
1.39      raeburn   838:             $pagetitle = 'Course/Community Requests';
                    839:             $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
                    840:             $domaintitle = &mt('Course/Community Domain');
1.75      raeburn   841:         } else {
                    842:             $pagetitle = 'Course/Community Requests';
                    843:             $pageinfo  = &mt('You do not have rights to request creation of courses or communities.');
                    844:             $earlyout = 1;
1.39      raeburn   845:         }
                    846:     }
                    847:     $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
1.75      raeburn   848:              '<p>'.$pageinfo.'</p>');
                    849:     if ($earlyout) {
                    850:         $r->print(&Apache::loncommon::end_page());
                    851:         return;
                    852:     }
                    853:     $r->print('<div>'.
1.27      raeburn   854:               &Apache::lonhtmlcommon::start_pick_box().
1.39      raeburn   855:               &Apache::lonhtmlcommon::row_title($domaintitle).
1.1       raeburn   856:               '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.72      raeburn   857:               &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms));
1.1       raeburn   858:     if (!$onchange) {
                    859:         $r->print('&nbsp;<input type="submit" name="godom" value="'.
                    860:                    &mt('Change').'" />');
                    861:     }
1.39      raeburn   862:     unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
1.72      raeburn   863:         $r->print('</form>'.&Apache::lonhtmlcommon::row_closure(1)."\n".
1.39      raeburn   864:                   &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
                    865:                   &Apache::loncommon::end_page());
                    866:         return;
                    867:     }
1.27      raeburn   868:     $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2       raeburn   869:     my $formname = 'requestcrs';
1.1       raeburn   870:     my $nexttext = &mt('Next');
1.27      raeburn   871:     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
                    872: <form name="mainmenu_action" method="post" action=""> 
1.1       raeburn   873: <select size="1" name="action" >
1.2       raeburn   874:  <option value="new">'.&mt('New request').'</option>
1.1       raeburn   875:  <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
                    876:  <option value="log">'.&mt('View request history').'</option>
1.27      raeburn   877: </select></form>'.
1.46      wenzelju  878:               &Apache::lonhtmlcommon::row_closure().
1.39      raeburn   879:               &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27      raeburn   880: <form name="mainmenu_coursetype" method="post" action="">
1.39      raeburn   881: <select size="1" name="crstype">');
                    882:     if (ref($can_request) eq 'HASH') {
                    883:         if (keys(%{$can_request}) > 1) {
                    884:             $r->print(' <option value="any">'.&mt('All types').'</option>');
                    885:         }
                    886:         if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
                    887:             foreach my $type (@{$types}) {
                    888:                 next unless($can_request->{$type});
                    889:                 my $selected = '';
                    890:                 if ($env{'form.crstype'} eq '') {
                    891:                     if ($type eq 'official') {
                    892:                         $selected = ' selected="selected"';
                    893:                     }
                    894:                 } else {
                    895:                     if ($type eq $env{'form.crstype'}) {
                    896:                         $selected = ' selected="selected"';
                    897:                     }
                    898:                 }
                    899:                 $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
                    900:                           '</option>'."\n");
1.4       raeburn   901:             }
                    902:         }
                    903:     }
1.27      raeburn   904:     $r->print('</select></form>'."\n".
                    905:               &Apache::lonhtmlcommon::row_closure(1)."\n".
                    906:               &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38      raeburn   907:               '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27      raeburn   908:               '<input type="hidden" name="state" value="crstype" />'."\n".
                    909:               '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
                    910:               '<input type="hidden" name="crstype" value="" />'."\n".
                    911:               '<input type="hidden" name="action" value="" />'."\n".
                    912:               '<input type="button" name="next" value="'.$nexttext.
                    913:               '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
                    914:               '</form></div>');
1.1       raeburn   915:     $r->print(&Apache::loncommon::end_page());
                    916:     return;
                    917: }
                    918: 
                    919: sub request_administration {
1.27      raeburn   920:     my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.66      raeburn   921:         $newinstcode,$codechk,$checkedcode,$description,$showcredits,
                    922:         $instcredits,$invalidcrosslist,$uname,$udom) = @_;
1.2       raeburn   923:     my $js;
1.16      raeburn   924:     if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2       raeburn   925:         $js =  <<END;
1.1       raeburn   926: 
                    927: function nextPage(formname,nextstate) {
                    928:     formname.state.value= nextstate;
                    929:     formname.submit();
                    930: }
1.16      raeburn   931: 
                    932: END
                    933:     }
                    934:     if (($action eq 'new') || ($action eq 'view')) {
                    935:         $js .= <<END;   
                    936: 
1.1       raeburn   937: function backPage(formname,prevstate) {
                    938:     formname.state.value = prevstate;
                    939:     formname.submit();
                    940: }
                    941: 
                    942: END
1.2       raeburn   943:     }
                    944:     if ($action eq 'new') {
                    945:         my $jsextra;
1.54      raeburn   946:         if (($state eq 'courseinfo') || ($state eq 'codepick')) {
1.2       raeburn   947:             $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31      raeburn   948:         } elsif ($state eq 'enrollment') {
                    949:             if (($env{'form.crstype'} eq 'official') && 
                    950:                 (&Apache::lonnet::auto_run('',$dom))) {
                    951:                 $js .= "\n".&section_check_javascript()."\n".&enrollment_lcsec_js();
                    952:             }
                    953:         } elsif ($state eq 'personnel') {
                    954:             $js .= "\n".&section_check_javascript()."\n".&personnel_lcsec_js();
1.1       raeburn   955:         }
1.40      raeburn   956:         my $title;
                    957:         if ($env{'form.crstype'} eq 'community') {
                    958:             $title = 'Request a community';
                    959:         } else {
                    960:             $title = 'Request a course';
                    961:         }
                    962:         $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
1.27      raeburn   963:         &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.66      raeburn   964:                             $codechk,$checkedcode,$description,$showcredits,
                    965:                             $instcredits,$invalidcrosslist);
1.2       raeburn   966:     } elsif ($action eq 'view') {
1.16      raeburn   967:         my $jsextra;
                    968:         my $formname = 'requestcrs';
                    969:         my $prev = $states->{$action}[$page-1];
                    970:         my $next = $states->{$action}[$page+1];
                    971:         if ($state eq 'pick_request') {
                    972:             $next = $states->{$action}[$page+1];
                    973:             $jsextra = &viewrequest_javascript($formname,$next);
                    974:         } elsif ($state eq 'details') {
                    975:             $jsextra = &viewdetails_javascript($formname);
                    976: 
                    977:         } elsif ($state eq 'cancel') {
                    978:             $jsextra = &viewcancel_javascript($formname);
                    979:         }
1.40      raeburn   980:         my $title;
                    981:         if ($env{'form.crstype'} eq 'community') {
                    982:             $title = 'Manage community requests';
                    983:         } else {
                    984:             $title = 'Manage course requests';
                    985:         }
                    986:         $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
1.16      raeburn   987:         my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11      raeburn   988:         if ($state eq 'pick_request') {
1.40      raeburn   989:             my $title;
                    990:             if ($env{'form.crstype'} eq 'community') {
                    991:                 $title = &mt('Pending community requests');
                    992:             } elsif ($env{'form.crstype'} eq 'official') {
                    993:                 $title = &mt('Pending requests for official courses');
                    994:             } elsif ($env{'form.crstype'} eq 'unofficial') {
                    995:                 $title = &mt('Pending requests for unofficial courses');
1.69      raeburn   996:             } elsif ($env{'form.crstype'} eq 'textbook') {
                    997:                 $title = &mt('Pending requests for textbook courses');
1.40      raeburn   998:             } else {
                    999:                 $title = &mt('Pending course/community requests'); 
                   1000:             }
                   1001:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.48      raeburn  1002:                       &print_request_status($dom,$action).'</form></div>');
1.16      raeburn  1003:         } elsif ($state eq 'details') {
                   1004:             my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1005:             my $origcnum = $env{'form.cnum'};
                   1006:             if ($origcnum eq '') {
                   1007:                 $origcnum = $env{'form.origcnum'};   
                   1008:             }
                   1009:             if ($env{'form.crstype'} eq 'official') {
                   1010:                 &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1011:                                                          \%cat_order,\@code_order);
                   1012:             }
1.40      raeburn  1013:             my $title;
                   1014:             if ($env{'form.crstype'} eq 'community') {
                   1015:                 $title = &mt('Community Request Details');
                   1016:             } else {
                   1017:                 $title = &mt('Course Request Details');
                   1018:             }
                   1019:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.26      raeburn  1020:                       &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66      raeburn  1021:                                     \@code_order,'','','','',$instcredits)."\n".
1.16      raeburn  1022:                       '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1.66      raeburn  1023:             my @excluded = &get_excluded_elements($dom,$states,'new','review',
                   1024:                                                   $showcredits);
1.16      raeburn  1025:             push(@excluded,'origcnum');
                   1026:             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
                   1027:             my $other = 'modify';
                   1028:             my %navtxt = &Apache::lonlocal::texthash (
                   1029:                                                       prev => 'Back',
                   1030:                                                       other => 'Modify Request',
                   1031:                                                       next => 'Cancel Request',
                   1032:                                                      );
1.31      raeburn  1033:             &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
                   1034:                                 $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16      raeburn  1035:             $r->print('</form>');
                   1036:         } elsif ($state eq 'cancel') {
1.40      raeburn  1037:             my $title;
                   1038:             if ($env{'form.crstype'} eq 'community') {
                   1039:                 $title = &mt('Cancel community request');
                   1040:             } else {
                   1041:                 $title = &mt('Cancel course request');
                   1042:             }
1.16      raeburn  1043:             my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40      raeburn  1044:             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16      raeburn  1045:                       $output);
1.66      raeburn  1046:             my @excluded = &get_excluded_elements($dom,$states,'view','cancel',
                   1047:                                                   $showcredits);
1.16      raeburn  1048:             $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
                   1049:             my %navtxt = &Apache::lonlocal::texthash (
                   1050:                                                       prev => 'Back',
                   1051:                                                       next => 'Confirm Cancellation',
                   1052:                                                      );
                   1053:             if ($result eq 'ok') {
1.31      raeburn  1054:                 &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16      raeburn  1055:                                     $navtxt{'next'},$state);
                   1056:             } else {
1.31      raeburn  1057:                 &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
                   1058:                                     '',$state);
1.16      raeburn  1059:             }
                   1060:             $r->print('</form>');
                   1061:         } elsif ($state eq 'removal') {
                   1062:             my $cnum = $env{'form.origcnum'};
                   1063:             my $statuskey = 'status:'.$dom.':'.$cnum;
                   1064:             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                   1065:                                                    $env{'user.domain'},$env{'user.name'});
                   1066:             my $currstatus = $userreqhash{$statuskey};
                   1067:             my ($result,$error); 
                   1068:             if (($currstatus eq 'approval') || ($currstatus eq 'pending')) { 
                   1069:                 my %status = (
                   1070:                                  $statuskey => 'cancelled',
                   1071:                              );
                   1072:                 my $statusresult = &Apache::lonnet::put('courserequests',\%status);
                   1073:                 if ($statusresult eq 'ok') {
                   1074:                     my $delresult = 
                   1075:                         &Apache::lonnet::del_dom('courserequestqueue',
                   1076:                                                  [$cnum.'_'.$currstatus],$dom);
                   1077:                     if ($delresult eq 'ok') {
                   1078:                         $result = 'ok';
                   1079:                     } else {
                   1080:                         $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
                   1081:                     }
                   1082:                 } else {
                   1083:                     $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
                   1084:                 }
                   1085:             } else {
                   1086:                 $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');  
                   1087:             }
                   1088:             $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
                   1089:                       '<input type="hidden" name="state" value="'.$state.'" />'."\n".
                   1090:                       '<input type="hidden" name="action" value="'.$action.'" />'."\n".
                   1091:                       '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
                   1092:                       '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
                   1093:             if ($result eq 'ok') {
1.40      raeburn  1094:                 if ($env{'form.crstype'} eq 'community') {
                   1095:                     $r->print(&mt('Your community request has been cancelled.'));
                   1096:                 } else {
                   1097:                     $r->print(&mt('Your course request has been cancelled.'));
                   1098:                 }
1.16      raeburn  1099:             } else {
                   1100:                 $r->print('<div class="LC_error">'.
                   1101:                           &mt('The request cancellation process was not complete.').
                   1102:                           '<br />'.$error.'</div>');
                   1103:             }
                   1104:             $r->print('</form>');
1.11      raeburn  1105:         }
1.26      raeburn  1106:     } elsif ($action eq 'display') {
                   1107:         my $formname = 'requestcrs';
                   1108:         my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1109:         if ($env{'form.crstype'} eq 'official') {
                   1110:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1111:                                                      \%cat_order,\@code_order);
                   1112:         }
1.40      raeburn  1113:         my ($title,$header);
                   1114:         if ($env{'form.crstype'} eq 'community') {
                   1115:             $title = 'Community Request';
                   1116:             $header = &mt('Community Request');
                   1117:         } else {
                   1118:             $title = 'Course Request';
                   1119:             $header = &mt('Course Request');
                   1120:         }
                   1121:         $r->print(&header($title,'','','',{ 'only_body' => 1}).
                   1122:                   $crumb."\n".'<h3>'.$header.'</h3>'.
1.26      raeburn  1123:                   &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66      raeburn  1124:                                 \@code_order,$uname,$udom,'','',$instcredits)."\n".
                   1125:                   '</div>'.
1.26      raeburn  1126:                   &close_popup_form());
1.1       raeburn  1127:     }
1.2       raeburn  1128:     $r->print(&Apache::loncommon::end_page());
1.1       raeburn  1129:     return;
                   1130: }
                   1131: 
1.31      raeburn  1132: sub enrollment_lcsec_js {
                   1133:     my %alerts = &section_check_alerts();
                   1134:     my $secname = $alerts{'badsec'};
                   1135:     my $secnone = $alerts{'reserved'};
                   1136:     my $output = '
                   1137: function validateEnrollSections(formname,nextstate) {
                   1138:     var badsectotal = 0;
                   1139:     var reservedtotal = 0;
                   1140:     var secTest = "";
                   1141: ';
                   1142:     for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   1143:         $output .= "
                   1144:     var selSec = 0;
                   1145:     for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
                   1146:         if (document.requestcrs.sec_".$i."[j].checked) {
                   1147:             selSec = document.requestcrs.sec_".$i."[j].value;
                   1148:         }
                   1149:         if (selSec == 1) {
                   1150:             secTest = validsection(document.requestcrs.loncapasec_".$i.");
                   1151:             if (secTest == 'badsec') {
                   1152:                 badsectotal++;
                   1153:             }
                   1154:             if (secTest == 'reserved') {
                   1155:                 reservedtotal++;
                   1156:             }
                   1157:         }
                   1158:     }
                   1159: ";
                   1160:     }
                   1161:     for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                   1162:         $output .= "
                   1163:     if (document.requestcrs.crosslist_".$i.".checked) {
                   1164:         secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
                   1165:         if (secTest == 'badsec') {
                   1166:             badsectotal++;
                   1167:         }
                   1168:         if (secTest == 'reserved') {
                   1169:             reservedtotal++;
                   1170:         }
                   1171:     }
                   1172: ";
                   1173:     }
                   1174:     $output .= "
                   1175:     if (badsectotal>0) {
                   1176:         alert('$secname');
                   1177:         return false;
                   1178:     }
                   1179:     if (reservedtotal>0) {
                   1180:         alert('$secnone');
                   1181:         return false;
                   1182:     }
                   1183:     formname.state.value= nextstate;
                   1184:     formname.submit();
                   1185:     return;
                   1186: }
                   1187: ";
                   1188:     return $output;
                   1189: }
                   1190: 
                   1191: sub personnel_lcsec_js {
                   1192:     my %alerts = &section_check_alerts();
                   1193:     my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
                   1194:     my $secnone = $alerts{'reserved'};
                   1195:     my $output = '
                   1196: function validatePersonnelSections(formname,nextstate) {
                   1197:     var badsectotal = 0;
                   1198:     var reservedtotal = 0;
                   1199:     var secTest = "";
                   1200: ';
                   1201:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1202:         $output .= "
                   1203:     if (document.requestcrs.person_".$i."_uname.value != '') {
                   1204:         secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
                   1205:         if (secTest == 'badsec') {
                   1206:             badsectotal++; 
                   1207:         }
                   1208:         if (secTest == 'reserved') {
                   1209:             reservedtotal++;
                   1210:         }
                   1211:     }
                   1212: ";
                   1213:     }
                   1214:     $output .= "
                   1215:     if (badsectotal > 0) {
                   1216:         alert('$secname');
                   1217:         return false;
                   1218:     } else {
                   1219:         if (reservedtotal > 0) {
                   1220:             alert('$secnone');
                   1221:             return false;
                   1222:         }
                   1223:     }
                   1224:     formname.state.value = nextstate;
                   1225:     formname.submit();
                   1226:     return;
                   1227: }
                   1228: ";
                   1229:     return $output;
                   1230: }
                   1231: 
                   1232: sub section_check_alerts {
                   1233:     my %lt = 
                   1234:         &Apache::lonlocal::texthash(
                   1235:             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.",
                   1236:             badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
                   1237:             separate => 'Separate multiple sections with a comma.'
                   1238:         );
                   1239:     return %lt;
                   1240: }
                   1241: 
                   1242: sub section_check_javascript {
                   1243:     return <<"END";
                   1244: function validsection(field,mult) {
                   1245:     var str = field.value;
                   1246:     var badsec=0;
                   1247:     var reserved=0;
                   1248:     if (window.RegExp) {
                   1249:         var badsecnum=0;
                   1250:         var reservednum=0;
                   1251:         var pattern=/[^a-zA-Z0-9]/; 
                   1252:         str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
                   1253:         str = str.replace(/[ ]{2,}/gi," ");
                   1254:         if (mult == '1') {
                   1255:             var sections = new Array();
                   1256:             sections = str.split(/\\s*[\\s,;:]\\s*/);
                   1257:             var i;
                   1258:             for (i=0; i<sections.length; i++) {
                   1259:                 if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
                   1260:                     if (pattern.test(sections[i])) {
                   1261:                         badsecnum++;
                   1262:                     } else {
                   1263:                         if (sections[i] == 'none') {
                   1264:                             reservednum++;
                   1265:                         }
                   1266:                     }
                   1267:                 }
                   1268:             }
                   1269:         } else {
                   1270:             if ((str != '') && (str != undefined) && (str != null)) {
                   1271:                 if (pattern.test(str)) {
                   1272:                     badsecnum++;
                   1273:                 } else {
                   1274:                     if (str == 'none') {
                   1275:                         reservednum++;
                   1276:                     }
                   1277:                 }
                   1278:             }
                   1279:         }
                   1280:         if (badsecnum > 0) {
                   1281:             return 'badsec';
                   1282:         }
                   1283:         if (reservednum > 0) {
                   1284:             return 'reserved';
                   1285:         }
                   1286:     }
                   1287:     return;
                   1288: }
                   1289: END
                   1290: }
                   1291: 
1.26      raeburn  1292: sub close_popup_form {
                   1293:     my $close= &mt('Close Window');
                   1294:     return << "END";
                   1295: <p><form name="displayreq" action="" method="post">
                   1296: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
                   1297: </form></p>
                   1298: END
                   1299: }
                   1300: 
1.27      raeburn  1301: sub get_instcode {
                   1302:     my ($dom) = @_;
                   1303:     my ($instcode,$numtitles);
                   1304:     my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
                   1305:     &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1306:                                              \%cat_order,\@code_order);
                   1307:     $numtitles = scalar(@codetitles);
                   1308:     if (@code_order > 0) {
                   1309:         my $message;
                   1310:         foreach my $item (@code_order) {
                   1311:             $instcode .= $env{'form.instcode_'.$item};
                   1312:         }
                   1313:     }
                   1314:     return ($instcode,$numtitles);
                   1315: }
                   1316: 
1.1       raeburn  1317: sub print_request_form {
1.27      raeburn  1318:     my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.66      raeburn  1319:         $description,$showcredits,$instcredits,$invalidcrosslist) = @_;
1.1       raeburn  1320:     my $formname = 'requestcrs';
1.2       raeburn  1321:     my ($next,$prev,$message,$output,$codepicker,$crstype);
                   1322:     $prev = $states->{$action}[$page-1];
                   1323:     $next = $states->{$action}[$page+1];
1.4       raeburn  1324:     my %navtxt = &Apache::lonlocal::texthash (
1.10      raeburn  1325:                                                prev => 'Back',
1.4       raeburn  1326:                                                next => 'Next',
                   1327:                                              );
1.2       raeburn  1328:     $crstype = $env{'form.crstype'};
1.34      raeburn  1329:     $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30      raeburn  1330:     my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
                   1331:         @disallowed);
1.1       raeburn  1332:     if ($crstype eq 'official') {
1.2       raeburn  1333:         if ($env{'form.instcode'} ne '') {
                   1334:             $instcode = $env{'form.instcode'};
1.27      raeburn  1335:         } elsif ($newinstcode ne '') {
                   1336:             $instcode = $newinstcode;
1.2       raeburn  1337:         }
1.27      raeburn  1338:         if ($checkedcode) {
                   1339:             if ($codechk eq 'valid') {
                   1340:                 $message = '<div class="LC_info">'.
                   1341:                            &mt('The chosen course category [_1] is valid.','<b>'.
                   1342:                            $instcode.'</b>').
                   1343:                            '<input type="hidden" name="instcode" value="'.
                   1344:                            $instcode.'" /></div>';
1.2       raeburn  1345:             } else {
                   1346:                 $message = '<div class="LC_warning">'.
1.27      raeburn  1347:                             &mt('No course was found matching your choice of institutional course category.');
                   1348:                 if ($codechk ne '') {
                   1349:                     $message .= '<br />'.$codechk;
                   1350:                 }
                   1351:                 $message .= '</div>';
1.2       raeburn  1352:                 $prev = 'crstype';
                   1353:             }
                   1354:             $r->print($message);
1.1       raeburn  1355:         }
1.2       raeburn  1356:     }
                   1357:     if ($prev eq 'crstype') {
1.4       raeburn  1358:         if ($crstype eq 'official') {
                   1359:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1360:                                                      \%cat_order,\@code_order);
                   1361:         }
1.2       raeburn  1362:         if (@code_order > 0) {
1.1       raeburn  1363:             $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
                   1364:                                            \%cat_titles,\%cat_order);
1.2       raeburn  1365:             if ($codepicker) {
1.34      raeburn  1366:                 $r->print(&mt('Specify the course to be created.').
                   1367:                           '<div>'.&Apache::lonhtmlcommon::start_pick_box().
                   1368:                           $codepicker.
1.2       raeburn  1369:                           &Apache::lonhtmlcommon::end_pick_box().'</div>');
                   1370:             } else {
1.20      raeburn  1371:                 $next = $states->{$action}[$page+2];
1.15      raeburn  1372:                 $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2       raeburn  1373:             }
                   1374:         } else {
1.20      raeburn  1375:             if ($crstype eq 'official') {
                   1376:                 $next = $states->{$action}[$page+2];
                   1377:             }
1.15      raeburn  1378:             $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1       raeburn  1379:         }
1.2       raeburn  1380:     } elsif ($prev eq 'codepick') {
1.27      raeburn  1381:         if ($instcode eq '') {
1.20      raeburn  1382:             $prev = $states->{$action}[$page-2];
                   1383:         }
1.36      raeburn  1384:         $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1.2       raeburn  1385:     } elsif ($state eq 'enrollment') {
1.4       raeburn  1386:         if ($crstype eq 'official') {
                   1387:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1388:                                                      \%cat_order,\@code_order);
                   1389:         }
1.2       raeburn  1390:         $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27      raeburn  1391:                                          \%cat_titles,\%cat_order,\@code_order,
1.66      raeburn  1392:                                          $showcredits,$instcredits,$invalidcrosslist));
1.2       raeburn  1393:     } elsif ($state eq 'personnel') {
1.27      raeburn  1394:         $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4       raeburn  1395:     } elsif ($state eq 'review') {
1.30      raeburn  1396:         my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
                   1397:         my $now = time;
                   1398:         for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1399:             my $personname = $env{'form.person_'.$i.'_uname'};
                   1400:             my $persondom = $env{'form.person_'.$i.'_dom'};
                   1401:             if (($personname =~ /^$match_username$/) && 
                   1402:                 ($persondom =~ /^$match_domain$/)) {
                   1403:                 if (&Apache::lonnet::domain($persondom)) {
                   1404:                     my $personhome = 
                   1405:                         &Apache::lonnet::homeserver($personname,$persondom);
                   1406:                     if ($personhome eq 'no_host') {
                   1407:                         if ($persondom ne $dom) {
                   1408:                             my $skipuser = 1;
                   1409:                             if ($env{'user.role.dc./'.$persondom.'/'}) {
                   1410:                                 my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
                   1411:                                 if (((!$start) || ($start < $now)) && 
                   1412:                                     ((!$end) || ($end > $now))) {
                   1413:                                     $skipuser = 0;
                   1414:                                 }
                   1415:                             }
                   1416:                             if ($skipuser) {
                   1417:                                 push(@disallowed,$i);
1.60      raeburn  1418:                                 $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1.30      raeburn  1419:                                 next;
                   1420:                             }
                   1421:                         }
1.60      raeburn  1422:                         my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
                   1423:                         if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
                   1424:                             my ($allowed,$msg,$authtype,$authparam) = 
1.30      raeburn  1425:                                 &check_newuser_rules($persondom,$personname,
                   1426:                                     \%alerts,\%rulematch,\%inst_results,
                   1427:                                     \%curr_rules,\%got_rules);
                   1428:                             if ($allowed) {
1.60      raeburn  1429:                                 my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
                   1430:                                 if ($usertype eq 'official') {
                   1431:                                     if ($authtype eq '') {
                   1432:                                         $authtype = $domdefaults{'auth_def'};
                   1433:                                         $authparam = $domdefaults{'auth_arg_def'};
                   1434:                                     }
                   1435:                                 } elsif ($usertype eq 'unofficial') {
                   1436:                                     if ($authtype eq '') {
                   1437:                                         $authtype = 'internal';
                   1438:                                         $authparam = '';
                   1439:                                     }
                   1440:                                 } else {
                   1441:                                     $authtype = $domdefaults{'auth_def'};
                   1442:                                     $authparam = $domdefaults{'auth_arg_def'};
                   1443:                                 }
                   1444:                                 if (($authtype eq '') ||
                   1445:                                     (($authtype =~/^krb/) && ($authparam eq ''))) {
                   1446:                                     push(@disallowed,$i);
                   1447:                                     $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
                   1448:                                     next;
                   1449:                                 }
1.30      raeburn  1450:                                 if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
                   1451:                                     if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
                   1452:                                         $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
                   1453:                                     }
                   1454:                                     if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
                   1455:                                         $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
                   1456:                                     }
                   1457:                                     if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
                   1458:                                         $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
                   1459:                                     }
                   1460:                                 }
                   1461:                             } else {
                   1462:                                 push(@disallowed,$i);
                   1463:                                 $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');  
                   1464:                             }
                   1465:                         } else {
                   1466:                             push(@disallowed,$i);
                   1467:                             $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
                   1468:                         }
                   1469:                     } else {
                   1470:                         my %userenv = 
                   1471:                             &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
                   1472:                         if ($env{'form.person_'.$i.'_lastname'} eq '') {
                   1473:                             $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
                   1474:                         }
                   1475:                         if ($env{'form.person_'.$i.'_firstname'} eq '') {
                   1476:                             $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
                   1477:                         }
                   1478:                         if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
                   1479:                             $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
                   1480:                         }
                   1481:                     }
                   1482:                 } elsif ($personname ne '') {
                   1483:                     push(@disallowed,$i);
                   1484:                     $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
                   1485:                 }
                   1486:             } elsif ($personname ne '') {
                   1487:                 push(@disallowed,$i);
                   1488:                 $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
                   1489:             }
                   1490:         }
1.16      raeburn  1491:         my $cnum;
                   1492:         if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
                   1493:             $cnum = $env{'form.origcnum'};
                   1494:         } else {
1.47      raeburn  1495:             my $gentype = 'Course';
                   1496:             if ($crstype eq 'community') {
                   1497:                 $gentype = 'Community';
                   1498:             }
                   1499:             $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1.16      raeburn  1500:         }
1.4       raeburn  1501:         &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1502:                                                  \%cat_order,\@code_order);
1.40      raeburn  1503:         if ($crstype eq 'community') {
                   1504:             $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
                   1505:         } else {
                   1506:             $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
                   1507:         }
1.66      raeburn  1508:         $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
1.16      raeburn  1509:                   '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.73      raeburn  1510:         my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                   1511:                                                      $env{'user.domain'});
                   1512:         my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'},
                   1513:                                                               $env{'user.domain'},$fullname,$env{'form.cdescr'});
                   1514:         if (ref($postprocess) eq 'HASH') {
                   1515:             if ($postprocess->{'reviewweb'}) {
                   1516:                 $r->print($postprocess->{'reviewweb'});
                   1517:             }
                   1518:         }
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.10      raeburn  1524:     }  elsif ($state eq 'process') {
                   1525:         if ($crstype eq 'official') {
                   1526:             &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                   1527:                                                      \%cat_order,\@code_order);
                   1528:         }
1.27      raeburn  1529:         my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1.66      raeburn  1530:                                                            \@code_order,$instcredits);
1.13      raeburn  1531:         $r->print($result);
1.27      raeburn  1532:         if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
                   1533:             if ($storeresult eq 'ok') {
1.65      raeburn  1534:                 $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
                   1535:                           &mt('Modify this request').'</a>'.('&nbsp;'x4).
                   1536:                           '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
                   1537:             }
                   1538:             if (&Apache::loncoursequeueadmin::author_prompt()) {
1.72      raeburn  1539:                 &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
                   1540:                                      $env{'form.crstype'},$storeresult);
1.65      raeburn  1541:             } elsif ($storeresult eq 'created') {
                   1542:                 $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
                   1543:             }
                   1544:         }
                   1545:     } elsif ($state eq 'reqauthor') {
                   1546:         my ($result,@links); 
                   1547:         if ($env{'form.requestauthor'}) {
                   1548:             $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
                   1549:             if ($result eq 'created') {
                   1550:                 my $role = 'au';
                   1551:                 my $spec = "$role./$env{'form.showdom'}/";
1.76      bisitz   1552:                 push(@links,&mt('Enter your Authoring Space with role: [_1]',
1.65      raeburn  1553:                                 '<a href="/adm/roles?selectrole=1&amp;'.$spec.'=1">'.
                   1554:                                 &Apache::lonnet::plaintext($role).'</a>'));
1.27      raeburn  1555:             }
1.65      raeburn  1556:         }
                   1557:         if (($env{'form.disposition'} eq 'created') &&
                   1558:             ($env{'form.cnum'} =~ /^$match_courseid$/) &&
                   1559:             ($env{'form.showdom'} =~ /^$match_domain$/)) {
                   1560:             my ($spec,$area,$role,$type);
                   1561:             my $role = 'cc';
                   1562:             my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
                   1563:             my $type = 'Course';
                   1564:             if ($env{'form.crstype'} eq 'community') {
                   1565:                 $type = 'Community';
                   1566:             }
                   1567:             my $showrole = &Apache::lonnet::plaintext($role,$type);
                   1568:             unshift(@links,&mt('Enter new course with role: [_1]',
                   1569:                                '<a href="/adm/roles?selectrole=1&amp;'.$spec.'=1">'.$showrole.'</a>'));
                   1570:         }
                   1571:         if (@links > 1) {
                   1572:             $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
                   1573:                           '<a href="/adm/roles">','</a>').'&nbsp'.&mt('Choose a role:').
                   1574:                        '<ul>');
                   1575:             foreach my $link (@links) {
                   1576:                 $r->print('<li>'.$link.'</li>');
                   1577:             }
                   1578:             $r->print('</ul>');
                   1579:         } elsif (@links == 1) {
                   1580:             $r->print('<p>'.$links[0].'</p>');
1.27      raeburn  1581:         }
1.1       raeburn  1582:     }
1.66      raeburn  1583:     my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits);
1.24      raeburn  1584:     if ($state eq 'personnel') {
                   1585:         push(@excluded,'persontotal');
                   1586:     }
1.30      raeburn  1587:     if ($state eq 'review') {
                   1588:         if (@disallowed > 0) {
                   1589:             my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
                   1590:             my @currsecs = &current_lc_sections();
                   1591:             if (@currsecs) {
                   1592:                 push(@items,'sec');
                   1593:             }
                   1594:             my $count = 0;
                   1595:             for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   1596:                 unless ($env{'form.person_'.$i.'_uname'} eq '') {
                   1597:                     if (grep(/^$i$/,@disallowed)) {
                   1598:                         foreach my $item (@items) {
                   1599:                             $env{'form.person_'.$i.'_'.$item} = '';
                   1600:                         }
                   1601:                     } else { 
                   1602:                         foreach my $item (@items) {
                   1603:                             $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
                   1604:                         }
                   1605:                     }
                   1606:                 }
                   1607:                 $count ++;
                   1608:             }
                   1609:             $env{'form.persontotal'} = $count;
                   1610:         }
                   1611:     }
1.27      raeburn  1612:     if ($state eq 'enrollment') {
1.61      raeburn  1613:         push(@excluded,('sectotal','crosslisttotal'));
1.27      raeburn  1614:     }
1.65      raeburn  1615:     if (($state eq 'process') || ($state eq 'reqauthor')) {
                   1616:         $r->print('</form>');
                   1617:     } else {
                   1618:         $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
                   1619:         &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
                   1620:                             $navtxt{'next'},$state);
                   1621:     }
1.16      raeburn  1622:     return;
                   1623: }
                   1624: 
1.72      raeburn  1625: sub print_author_prompt {
                   1626:     my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_;
1.76      bisitz   1627:     $r->print('<h3>'.&mt('Access to Authoring Space').'</h3>'.
1.72      raeburn  1628:               '<p>'.
                   1629:               &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
                   1630:               '<br />'.
1.76      bisitz   1631:               &mt('By contrast, items created in Authoring Space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
                   1632:               '<p>'.&mt('Request Authoring Space access now?').
1.72      raeburn  1633:               '<span class="LC_nobreak">&nbsp;'.
                   1634:               '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
                   1635:               ('&nbsp;'x2).
                   1636:               '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
                   1637:               '</span></p>'.
                   1638:               '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
                   1639:               '<input type="hidden" name="state" value="reqauthor" />'.
                   1640:               '<input type="hidden" name="action" value="'.$action.'" />'.
                   1641:               '<input type="hidden" name="cnum" value="'.$cnum.'" />'.
                   1642:               '<input type="hidden" name="showdom" value="'.$showdom.'" />'.
                   1643:               '<input type="hidden" name="crstype" value="'.$crstype.'" />'.
                   1644:               '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
                   1645:               '<br />');
                   1646: }    
                   1647: 
1.60      raeburn  1648: sub get_usertype {
                   1649:     my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1.30      raeburn  1650:     my ($rules,$ruleorder) =
                   1651:         &Apache::lonnet::inst_userrules($persondom,'username');
                   1652:     my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1.60      raeburn  1653:                                                          $rules,$curr_rules,$got_rules);
                   1654:     return $usertype;
1.30      raeburn  1655: }
                   1656: 
                   1657: sub check_newuser_rules {
                   1658:     my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
                   1659:         $got_rules) = @_;
                   1660:     my $allowed = 1;
                   1661:     my $newuser = 1;
1.60      raeburn  1662:     my ($checkhash,$userchkmsg,$authtype,$authparam);
1.30      raeburn  1663:     my $checks = { 'username' => 1 };
                   1664:     $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
                   1665:     &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
                   1666:                                         $inst_results,$curr_rules,$got_rules);
                   1667:     if (ref($alerts->{'username'}) eq 'HASH') {
                   1668:         if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
                   1669:             my $domdesc =
                   1670:                 &Apache::lonnet::domain($persondom,'description');
                   1671:             if ($alerts->{'username'}{$persondom}{$personname}) {
                   1672:                 if (ref($curr_rules->{$persondom}) eq 'HASH') {
                   1673:                     $userchkmsg =
                   1674:                         &Apache::loncommon::instrule_disallow_msg('username',
                   1675:                                                                   $domdesc,1).
                   1676:                         &Apache::loncommon::user_rule_formats($persondom,
                   1677:                             $domdesc,$curr_rules->{$persondom}{'username'},
                   1678:                             'username');
                   1679:                 }
                   1680:                 $allowed = 0;
                   1681:             }
                   1682:         }
                   1683:     }
1.60      raeburn  1684:     if ($allowed) {
                   1685:         if (ref($rulematch) eq 'HASH') {
                   1686:             if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
                   1687:                 my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
                   1688:                 my ($rules,$ruleorder) =
                   1689:                     &Apache::lonnet::inst_userrules($persondom,'username');
                   1690:                 if (ref($rules) eq 'HASH') {
                   1691:                     if (ref($rules->{$matchedrule}) eq 'HASH') {
                   1692:                         $authtype = $rules->{$matchedrule}{'authtype'};
                   1693:                         $authparam = $rules->{$matchedrule}{'authparm'};
                   1694:                     }
                   1695:                 }
                   1696:             }
                   1697:         }
                   1698:     }
                   1699:     return ($allowed,$userchkmsg,$authtype,$authparam);
1.30      raeburn  1700: }
                   1701: 
1.16      raeburn  1702: sub get_excluded_elements {
1.66      raeburn  1703:     my ($dom,$states,$action,$state,$showcredits) = @_;
1.2       raeburn  1704:     my @excluded = ('counter');
1.66      raeburn  1705:     my ($elements,$instcredits) = &form_elements($dom,$showcredits);
1.2       raeburn  1706:     if (ref($states) eq 'HASH') {
                   1707:         if (ref($states->{$action}) eq 'ARRAY') {
                   1708:             my @items = @{$states->{$action}};
                   1709:             my $numitems = scalar(@items);
                   1710:             if ($numitems) {
                   1711:                 for (my $i=$numitems-1; $i>=0; $i--) {
1.66      raeburn  1712:                     if ((ref($elements) eq 'HASH') && 
                   1713:                         (ref($elements->{$action}) eq 'HASH')) {
                   1714:                         if (ref($elements->{$action}{$items[$i]}) eq 'HASH') {
                   1715:                             foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) {
1.2       raeburn  1716:                                 push(@excluded,$key);
                   1717:                             }
                   1718:                         }
                   1719:                     }
                   1720:                     last if ($items[$i] eq $state);
                   1721:                 }
                   1722:             }
                   1723:         }
                   1724:     }
                   1725:     if (grep(/^instcode_/,@excluded)) {
                   1726:         push(@excluded,'instcode');
1.1       raeburn  1727:     }
1.16      raeburn  1728:     return @excluded;
1.1       raeburn  1729: }
                   1730: 
1.2       raeburn  1731: sub print_enrollment_menu {
1.27      raeburn  1732:     my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1.66      raeburn  1733:         $showcredits,$instcredits,$invalidcrosslist) =@_;
                   1734:     my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits,
                   1735:         $creditsrow,$domdefcredits);
1.2       raeburn  1736:     my $starttime = time;
                   1737:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                   1738: 
                   1739:     my %accesstitles = (
                   1740:                           'start' => 'Default start access',
1.16      raeburn  1741:                            'end'   => 'Default end access',
1.2       raeburn  1742:                        );
                   1743:     my %enrolltitles = (
                   1744:                            'start' => 'Start auto-enrollment',
                   1745:                            'end'   => 'End auto-enrollment',
                   1746:                        );
1.66      raeburn  1747:     if ($showcredits) {
                   1748:         unless ($env{'form.crstype'} eq 'community') {
                   1749:             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
                   1750:             $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'};
                   1751:         }
                   1752:     }
1.2       raeburn  1753:     if ($env{'form.crstype'} eq 'official') {
                   1754:         if (&Apache::lonnet::auto_run('',$dom)) {
1.27      raeburn  1755:             $output = &show_invalid_crosslists($invalidcrosslist);
                   1756:             my ($section_form,$crosslist_form);
1.61      raeburn  1757:             if ($instcode ne '') {
                   1758:                 $section_form = &inst_section_selector($dom,$instcode);
                   1759:                 if ($section_form eq '') {
                   1760:                     my $sectotal = $env{'form.sectotal'};
                   1761:                     if (!$sectotal) {
                   1762:                         $sectotal = 1;
                   1763:                     }
                   1764:                     if ($env{'form.addsection'}) {
                   1765:                         $sectotal ++;
                   1766:                     }
                   1767:                     for (my $i=0; $i<$sectotal; $i++) {
                   1768:                         $section_form .= &sections_form($dom,$instcode,$i);
                   1769:                     }
                   1770:                     if ($section_form) {
                   1771:                         $section_form .=
                   1772:                     &Apache::lonhtmlcommon::row_title(&mt('Add another')).
                   1773:                     '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
                   1774:                     '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
                   1775:                     ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
                   1776:                    "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
                   1777:                     }
                   1778:                 }
                   1779:             }
1.27      raeburn  1780:             if ($section_form) {
                   1781:                 $sections = &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  1782:                             '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
                   1783:                             '&nbsp;'.&mt('Sections for auto-enrollment').'</h3>'.
1.27      raeburn  1784:                             &Apache::lonhtmlcommon::row_closure(1).
                   1785:                             $section_form;
                   1786:             }
1.2       raeburn  1787:             my $crosslisttotal = $env{'form.crosslisttotal'};
1.24      raeburn  1788:             if (!$crosslisttotal) {
1.2       raeburn  1789:                 $crosslisttotal = 1;
                   1790:             }
                   1791:             if ($env{'form.addcrosslist'}) {
                   1792:                 $crosslisttotal ++;
                   1793:             }
                   1794:             for (my $i=0; $i<$crosslisttotal; $i++) {
                   1795:                 $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles, 
                   1796:                                                   $cat_titles,$cat_order,$i);
                   1797:             }
                   1798:             if ($crosslist_form) { 
                   1799:                 $crosslist_form .= 
1.40      raeburn  1800:                     &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2       raeburn  1801:                     '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
                   1802:                     '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
                   1803:                     ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27      raeburn  1804:                    "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
                   1805:                 $sections .=  &Apache::lonhtmlcommon::row_headline.
1.61      raeburn  1806:                               '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').'&nbsp;'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1.27      raeburn  1807:                               &Apache::lonhtmlcommon::row_closure(1).
                   1808:                               $crosslist_form;
1.2       raeburn  1809:             }
1.34      raeburn  1810:             $hasauto = 1;
1.27      raeburn  1811:             $autoenroll = 
1.34      raeburn  1812:                 &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').'&nbsp;'.&mt('Add registered students automatically')).
1.2       raeburn  1813:                 '<span class="LC_nobreak"><label>'.
                   1814:                 '<input type="radio" name="autoadds" value="1">'.
                   1815:                 &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
                   1816:                 '<input type="radio" name="autoadds" value="0" checked="checked">'.
                   1817:                 &mt('No').'</label></span>'.
1.27      raeburn  1818:                 &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1819:                 &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').'&nbsp;'.&mt('Drop unregistered students automatically')).
1.2       raeburn  1820:                 '<span class="LC_nobreak"><label>'.
                   1821:                 '<input type="radio" name="autodrops" value="1">'.
                   1822:                 &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
                   1823:                 '<input type="radio" name="autodrops" value="0" checked="checked">'.
                   1824:                 &mt('No').'</label></span>'. 
1.27      raeburn  1825:                 &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1826:                 &date_setting_table($starttime,$endtime,$formname,'enroll',
1.66      raeburn  1827:                                     $hasauto,undef,%enrolltitles);
                   1828:             if ($showcredits) {
                   1829:                 if ($instcredits) {
                   1830:                     $creditsrow = &mt('[quant,_1,credit]',$instcredits);
                   1831:                 } else {
                   1832:                     $creditsrow = '<span class="LC_nobreak">'.
                   1833:                                   '<input type="text" size="3" name="coursecredits"'.
                   1834:                                   ' value="'.$domdefcredits.'" />';
                   1835:                 }
                   1836:                 $hascredits = 1;
                   1837:             }
                   1838:         }
1.69      raeburn  1839:     } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66      raeburn  1840:         if ($showcredits) {
                   1841:             $creditsrow = '<span class="LC_nobreak">'.
                   1842:                           '<input type="text" size="3" name="coursecredits"'.
                   1843:                           ' value="'.$domdefcredits.'"/>';
                   1844:             $hascredits = 1;
1.2       raeburn  1845:         }
                   1846:     }
1.27      raeburn  1847:     my $access_dates = 
1.34      raeburn  1848:         &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1.66      raeburn  1849:                             $hascredits,%accesstitles);
1.27      raeburn  1850:     $output .= &Apache::lonhtmlcommon::start_pick_box();
                   1851:     if ($sections) {
                   1852:         $output .=  $sections;
                   1853:     }
                   1854:     if ($autoenroll) {
                   1855:         $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
                   1856:                    '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
                   1857:                    &Apache::lonhtmlcommon::row_closure(1).
                   1858:                    $autoenroll;
                   1859:     }
                   1860:     if ($access_dates) {
                   1861:         my $header = &mt('Access dates for students');
                   1862:         if ($env{'form.crstype'} eq 'community') {
                   1863:             $header = &mt('Access dates for community members');
                   1864:         }
                   1865:         $output .= &Apache::lonhtmlcommon::row_headline('Access').
                   1866:                    '<h3>'.$header.'</h3>'.
                   1867:                    &Apache::lonhtmlcommon::row_closure(1).
1.66      raeburn  1868:                    $access_dates;
                   1869:     }
                   1870:     if ($creditsrow) {
                   1871:         $output .= &Apache::lonhtmlcommon::row_headline('Credits').
                   1872:                    '<h3>'.&mt('Credits earned by students').'</h3>'.
                   1873:                    &Apache::lonhtmlcommon::row_closure(1).
                   1874:                    &Apache::lonhtmlcommon::row_title(&mt('Default credits')).
                   1875:                    $creditsrow.
                   1876:                    &Apache::lonhtmlcommon::row_closure(1);
1.2       raeburn  1877:     }
1.27      raeburn  1878:     return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
                   1879:            &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2       raeburn  1880: }
                   1881: 
1.27      raeburn  1882: sub show_invalid_crosslists {
                   1883:     my ($invalidcrosslist) = @_;
                   1884:     my $output;
                   1885:     if (ref($invalidcrosslist) eq 'ARRAY') {
                   1886:         if (@{$invalidcrosslist} > 0) {
                   1887:             $output = '<div class="LC_warning">'.
                   1888:                       &mt('The following crosslisted courses were invalid:').'<ul>';
                   1889:             foreach my $item (@{$invalidcrosslist}) {
                   1890:                 $output .= '<li>'.$item.'</li>';
                   1891:             }
                   1892:             $output .= '</ul></div><br />';
                   1893:         }
                   1894:     }
                   1895:     return $output;
                   1896: }
                   1897: 
                   1898: 
1.1       raeburn  1899: sub inst_section_selector {
1.2       raeburn  1900:     my ($dom,$instcode) = @_;
                   1901:     my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
                   1902:     my $sectotal = scalar(@sections);
1.1       raeburn  1903:     my $output;
1.2       raeburn  1904:     if ($sectotal) {
1.27      raeburn  1905:         $output .=  &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2       raeburn  1906:                     &Apache::loncommon::start_data_table().
                   1907:                     &Apache::loncommon::start_data_table_row().
                   1908:                     '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24      raeburn  1909:                     'value="'.$sectotal.'"  /></th>'.
1.2       raeburn  1910:                     '<th>'.&mt('Institutional Section').'</th>'.
1.34      raeburn  1911:                     '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
                   1912:                           '&nbsp;'.&mt('LON-CAPA section').'</th>'.
1.2       raeburn  1913:                     &Apache::loncommon::end_data_table_row();
                   1914:         for (my $i=0; $i<@sections; $i++) {
1.1       raeburn  1915:             my $colflag = $i%2;
1.31      raeburn  1916:             my $secon = ' checked="checked"';
                   1917:             my $secoff = '';
1.24      raeburn  1918:             if ($env{'form.origcnum'}) {
1.31      raeburn  1919:                 $secoff = $secon;
                   1920:                 $secon='';
1.24      raeburn  1921:             }
1.1       raeburn  1922:             $output .= &Apache::loncommon::start_data_table_row().
1.31      raeburn  1923:                        '<td><label><input type="radio" name="sec_'.$i.
                   1924:                        '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
                   1925:                        ('&nbsp;'x2).'<label><input type="radio" name="sec_'.$i.
                   1926:                         '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
                   1927:                        '<td align="center">'.$sections[$i].
1.1       raeburn  1928:                        '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2       raeburn  1929:                        $sections[$i].'" /></td>'.
1.1       raeburn  1930:                        '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2       raeburn  1931:                        '" value="'.$sections[$i].'" /></td>'.
1.1       raeburn  1932:                        &Apache::loncommon::end_data_table_row();
                   1933:         }
1.2       raeburn  1934:         $output .= &Apache::loncommon::end_data_table().
                   1935:                    &Apache::lonhtmlcommon::row_closure();
1.1       raeburn  1936:     }
                   1937:     return $output;
                   1938: }
                   1939: 
1.2       raeburn  1940: sub date_setting_table {
1.66      raeburn  1941:     my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_;
1.2       raeburn  1942:     my ($perpetual,$table);
1.14      raeburn  1943:     my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2       raeburn  1944:                                                         $starttime,'','','',1,'','','',1);
1.14      raeburn  1945:     my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2       raeburn  1946:                                                       $endtime,'','','',1,'','','',1);
1.27      raeburn  1947:     my $closure = '';
1.14      raeburn  1948:     if ($prefix eq 'access') {
1.2       raeburn  1949:         $perpetual = ' <span class="LC_nobreak"><label>'.
                   1950:                      '<input type="checkbox" name="no_end_date" />'.
                   1951:                      &mt('No end date').'</label></span>';
1.66      raeburn  1952:         unless ($hascredits) {
                   1953:             $closure = '1';
                   1954:         }
1.2       raeburn  1955:     }
1.34      raeburn  1956: 
                   1957:     my %help_item = (
                   1958:                       access => {
                   1959:                                   start => 'Course_Request_Access_Start', 
                   1960:                                   end   => 'Course_Request_Access_End',
                   1961:                                 },
                   1962:                       enroll => {
                   1963:                                   start => 'Course_Request_Enroll_Start',
                   1964:                                   end   => 'Course_Request_Enroll_End',
                   1965:                                 },
                   1966:                      );
                   1967:     if ($hasauto) {
                   1968:         $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
                   1969:         $help_item{'access'}{'end'}   = 'Course_Request_RegAccess_End';
                   1970:     }
                   1971: 
                   1972:     $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1.46      wenzelju 1973:              '&nbsp;'.&mt($datetitles{'start'})).$startform.
1.27      raeburn  1974:              &Apache::lonhtmlcommon::row_closure(1).
1.34      raeburn  1975:              &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1.46      wenzelju 1976:              '&nbsp;'.&mt($datetitles{'end'})).$endform.$perpetual.
1.27      raeburn  1977:              &Apache::lonhtmlcommon::row_closure($closure);
1.2       raeburn  1978:     return $table;
                   1979: }
                   1980: 
                   1981: sub print_personnel_menu {
1.27      raeburn  1982:     my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
                   1983:     my $output;
                   1984:     if ($crstype eq 'official') {
                   1985:         if (&Apache::lonnet::auto_run('',$dom)) {
                   1986:             $output .= &show_invalid_crosslists($invalidcrosslist);
                   1987:         }  
                   1988:     }
                   1989:     $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2       raeburn  1990:     my $persontotal = $env{'form.persontotal'};
1.16      raeburn  1991:     if ((!defined($persontotal)) || (!$persontotal)) {
1.2       raeburn  1992:         $persontotal = 1;
                   1993:     }
                   1994:     if ($env{'form.addperson'}) {
                   1995:         $persontotal ++;
                   1996:     }
1.13      raeburn  1997:     my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2       raeburn  1998: 
1.8       raeburn  1999:     my $type = 'Course';
                   2000:     if ($crstype eq 'community') {
                   2001:         $type = 'Community';
                   2002:     }
1.41      raeburn  2003:     my $roleoptions;
                   2004:     my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2       raeburn  2005:     foreach my $role (@roles) {
1.28      raeburn  2006:         my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2       raeburn  2007:         $roleoptions .= '  <option value="'.$role.'">'.$plrole.'</option>'."\n";
                   2008:     }
                   2009:     my %customroles=&Apache::lonuserutils::my_custom_roles();
                   2010:     if (keys(%customroles) > 0) {
                   2011:         foreach my $cust (sort(keys(%customroles))) {
1.28      raeburn  2012:             my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2       raeburn  2013:             $roleoptions .= '  <option value="'.$custrole.'">'.$cust.'</option>'."\n";
                   2014:         }
                   2015:     }
                   2016: 
1.30      raeburn  2017:     my @currsecs = &current_lc_sections();
1.2       raeburn  2018: 
                   2019:     my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
                   2020:     if (@currsecs) {
                   2021:         my $existsize = scalar(@currsecs);
                   2022:         if ($existsize > 3) {
                   2023:             $existsize = 3;
                   2024:         }
                   2025:         if ($existsize > 1) {
                   2026:             $existmult = ' multiple="multiple" size="'.$existsize.'" ';
                   2027:         }
                   2028:         @currsecs = sort { $a <=> $b } (@currsecs);
                   2029:         $existtitle = &mt('Official').':&nbsp;';
                   2030:         $existops = '<option value="">'.&mt('None').'</option>';
                   2031:         foreach my $sec (@currsecs) {
                   2032:             $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
                   2033:         }
                   2034:         $seccolspan = ' colspan="2"';
                   2035:         $newtitle = &mt('Other').':&nbsp;';
                   2036:     }
                   2037: 
1.27      raeburn  2038:     if ($persontotal) {
1.32      raeburn  2039:         my %lt = &Apache::lonlocal::texthash(
                   2040:             community => 'Requestor is automatically assigned Coordinator role.',
                   2041:             official => 'Requestor is automatically assigned Course Coordinator role.',
                   2042:         );
                   2043:         $lt{'unofficial'} = $lt{'official'};
1.69      raeburn  2044:         $lt{'textbook'} = $lt{'textbook'};
1.27      raeburn  2045:         $output .= &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  2046:                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').'&nbsp;'.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27      raeburn  2047:     }
1.2       raeburn  2048:     for (my $i=0; $i<$persontotal; $i++) { 
                   2049:         my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
                   2050:         my $linkargstr = join("','",@linkargs);
1.29      raeburn  2051:         my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2       raeburn  2052:         my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29      raeburn  2053:                        "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2       raeburn  2054:         my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
                   2055:                                                             1,$onchange).
1.29      raeburn  2056:                         '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2       raeburn  2057:         my %form_elems;
                   2058:         foreach my $item (@items) {
                   2059:             next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
                   2060:             $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
                   2061:                                  'value="" readonly="readonly" />';
                   2062:         }
                   2063:         my $roleselector = '<select name="person_'.$i.'_role">'."\n".
                   2064:                            $roleoptions.'</select>';
                   2065:         my $sectionselector;
                   2066:         if (@currsecs) {
                   2067:             $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
                   2068:                                $existmult.'>'."\n".$existops.'</select>'.('&nbsp;' x3);
                   2069:         }
                   2070:         $sectionselector .= $newtitle.
1.14      raeburn  2071:             '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29      raeburn  2072:         my $usersrchlinktxt = &mt('Search for user');
                   2073:         my $usersrchlink =  &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
                   2074:                             $usersrchlinktxt);
                   2075:         my $userchklinktxt = &mt('Check username');
                   2076:         my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
                   2077:                             $userchklinktxt,'checkusername');
1.2       raeburn  2078:         $output .= 
1.29      raeburn  2079:             &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
                   2080:             '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
                   2081:             '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
                   2082:             &mt('Username').':&nbsp;'.$uname_form.'&nbsp;'.$userchklink.'</span><br />'."\n".
                   2083:             '<span class="LC_nobreak">'.&mt('Domain').':&nbsp;'.$udom_form.'</span></td>'.
                   2084:             '</tr>'."\n".'<tr>'.
1.13      raeburn  2085:             '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
                   2086:             '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
                   2087:             '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34      raeburn  2088:             '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').'&nbsp;'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
                   2089:             '<td'.$seccolspan.' align="center" valign="top">'.
                   2090:             &Apache::loncommon::help_open_topic('Course_Request_Rolesection').'&nbsp;'.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2       raeburn  2091:             '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
                   2092:     }
1.40      raeburn  2093:     $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2       raeburn  2094:                '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
                   2095:                '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
                   2096:                ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
                   2097:                "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40      raeburn  2098:                &Apache::lonhtmlcommon::end_pick_box().'</div>';
                   2099:     if ($crstype eq 'community') {
                   2100:         $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>';
                   2101:     } else {
                   2102:         $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>';
                   2103:     }
1.2       raeburn  2104:     return $output;
                   2105: }
                   2106: 
1.30      raeburn  2107: sub current_lc_sections {
                   2108:     my @currsecs;
                   2109:     if ($env{'form.sectotal'}) {
                   2110:         for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31      raeburn  2111:             if ($env{'form.sec_'.$i}) { 
                   2112:                 if (defined($env{'form.loncapasec_'.$i})) {
                   2113:                     my $lcsec = $env{'form.loncapasec_'.$i};
                   2114:                     unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
                   2115:                         push(@currsecs,$lcsec);
                   2116:                     }
1.30      raeburn  2117:                 }
                   2118:             }
                   2119:         }
                   2120:     }
                   2121:     return @currsecs;
                   2122: }
                   2123: 
1.48      raeburn  2124: sub sorted_request_history {
1.49      raeburn  2125:     my ($dom,$action,$curr_req) = @_;
                   2126:     my ($after,$before,$statusfilter,$crstypefilter);
                   2127:     if ($env{'form.status'} ne '') {
                   2128:         $statusfilter = $env{'form.status'};
                   2129:     }
                   2130:     if ($env{'form.crstype'} ne '') {
                   2131:         $crstypefilter = $env{'form.crstype'};
                   2132:     }
                   2133:     if (ref($curr_req) eq 'HASH') {
                   2134:         $after = $curr_req->{'requested_after_date'},
                   2135:         $before = $curr_req->{'requested_before_date'};
                   2136:         $statusfilter = $curr_req->{'status'};
                   2137:         $crstypefilter = $curr_req->{'crstype'};
                   2138:     }
1.14      raeburn  2139:     my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
                   2140:                                            $env{'user.name'},'^status:'.$dom);
1.48      raeburn  2141:     my %queue_by_date;
1.37      raeburn  2142:     my ($types,$typenames) = &Apache::loncommon::course_types();
1.14      raeburn  2143:     foreach my $key (keys(%statusinfo)) {
1.48      raeburn  2144:         if ($action eq 'view') {
                   2145:             next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
                   2146:         } else {
1.49      raeburn  2147:             next unless (($statusfilter eq 'any') ||
                   2148:                           ($statusfilter eq $statusinfo{$key}));
1.48      raeburn  2149:         }
                   2150:         (undef,my($cdom,$cnum)) = split(':',$key);
                   2151:         next if ($cdom ne $dom);   
                   2152:         my $requestkey = $cdom.'_'.$cnum;
                   2153:         if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                   2154:             my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                   2155:                                                    $env{'user.domain'},$env{'user.name'});
                   2156:             my $entry;
                   2157:             my $reqtime = $history{'reqtime'};
                   2158:             my $lastupdate = $history{'timestamp'};
                   2159:             my $crstype = $history{'crstype'};
                   2160:             my $disposition = $history{'disposition'};
                   2161:             my $status = $history{'status'};
1.73      raeburn  2162:             my $uniquecode = $history{'code'}; 
1.48      raeburn  2163:             if ($action eq 'view') {
1.14      raeburn  2164:                 next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1.48      raeburn  2165:             } else {
                   2166:                 next if (($reqtime < $after) || ($reqtime > $before));
                   2167:             }
1.49      raeburn  2168:             next unless (($crstypefilter eq 'any') || 
                   2169:                          ($crstypefilter eq $crstype));
1.48      raeburn  2170:             if ($action eq 'view') {
1.14      raeburn  2171:                 next unless (($disposition eq 'approval') || 
                   2172:                              ($disposition eq 'pending'));
1.48      raeburn  2173:             }
                   2174:             if (ref($history{'details'}) eq 'HASH') {
                   2175:                 $entry = $requestkey.':'.$crstype.':'.
                   2176:                          &escape($history{'details'}{'cdescr'});
                   2177:                 if ($action eq 'log') {
1.73      raeburn  2178:                     $entry .= ':'.$uniquecode.':'.$lastupdate.':';
1.48      raeburn  2179:                     if ($statusinfo{$key} ne '') {
                   2180:                         $entry .= $statusinfo{$key};
                   2181:                     } elsif ($status ne '') {
                   2182:                         $entry .= $status;
                   2183:                     } else {
                   2184:                         $entry .= $disposition;
1.14      raeburn  2185:                     }
                   2186:                 }
1.48      raeburn  2187:                 if ($crstype eq 'official') {
                   2188:                     $entry .= ':'.&escape($history{'details'}{'instcode'}); 
                   2189:                 }
                   2190:             }
                   2191:             if ($entry ne '') {
                   2192:                 if (exists($queue_by_date{$reqtime})) {
                   2193:                     if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
                   2194:                         push(@{$queue_by_date{$reqtime}},$entry);
1.10      raeburn  2195:                     }
1.48      raeburn  2196:                 } else {
                   2197:                     @{$queue_by_date{$reqtime}} = ($entry);
1.10      raeburn  2198:                 }
                   2199:             }
                   2200:         }
                   2201:     }
1.48      raeburn  2202:     return %queue_by_date;
                   2203: }
                   2204: 
                   2205: sub print_request_status {
                   2206:     my ($dom,$action) = @_;
                   2207:     my %queue_by_date = &sorted_request_history($dom,$action);
1.10      raeburn  2208:     my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.48      raeburn  2209:     my $formname = 'requestcrs';
                   2210:     my ($types,$typenames) = &Apache::loncommon::course_types();
                   2211:     my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.16      raeburn  2212: 
1.10      raeburn  2213:               '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16      raeburn  2214:               '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
                   2215:               '<input type="hidden" name="showdom" value="" />'."\n".
                   2216:               '<input type="hidden" name="cnum" value="" />'."\n";
1.10      raeburn  2217:     if (@sortedtimes > 0) {
1.40      raeburn  2218:         my $desctitle;
                   2219:         if ($env{'form.crstype'} eq 'any') {
                   2220:             $desctitle = &mt('Course/Community Description')
                   2221:         } elsif ($env{'form.crstype'} eq 'community') {
                   2222:             $desctitle = &mt('Community Description')
                   2223:         } else {
                   2224:             $desctitle = &mt('Course Description');
                   2225:         }
1.10      raeburn  2226:         $output .= &Apache::loncommon::start_data_table().
                   2227:                    &Apache::loncommon::start_data_table_header_row().
                   2228:                    '<th>'.&mt('Action').'</th>'.
1.40      raeburn  2229:                    '<th>'.$desctitle.'</th>'.
1.14      raeburn  2230:                    '<th>'.&mt('Domain').'</th>';
                   2231:         if ($env{'form.crstype'} eq 'any') {
1.10      raeburn  2232:             $output .= '<th>'.&mt('Type').'</th>';
                   2233:         }
1.14      raeburn  2234:         if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10      raeburn  2235:             $output .= '<th>'.&mt('Institutional Code').'</th>';
                   2236:         }
                   2237:         $output .= '<th>'.&mt('Date requested').'</th>'.
                   2238:                    &Apache::loncommon::end_data_table_header_row();
                   2239:         my $count = 0;
                   2240:         foreach my $item (@sortedtimes) {
                   2241:             my $showtime = &Apache::lonlocal::locallocaltime($item);
                   2242:             if (ref($queue_by_date{$item}) eq 'ARRAY') {
                   2243:                 foreach my $request (sort(@{$queue_by_date{$item}})) {
                   2244:                     my ($key,$type,$desc,$instcode) = split(':',$request);
                   2245:                     my ($cdom,$cnum) = split('_',$key);
                   2246:                     $output .= &Apache::loncommon::start_data_table_row().
1.16      raeburn  2247:      '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14      raeburn  2248:      '<td>'.&unescape($desc).'</td>'.
                   2249:      '<td>'.$cdom.'</td>';
                   2250:                     if ($env{'form.crstype'} eq 'any') {
1.35      raeburn  2251:                         my $typename;
                   2252:                         if (ref($typenames) eq 'HASH') {
                   2253:                             $typename = &mt($typenames->{$type});
                   2254:                         }
1.14      raeburn  2255:                         if ($typename eq '') {
                   2256:                             $typename = &mt('Unknown type');
                   2257:                         }
                   2258:                         $output .= '<td>'.$typename.'</td>';
1.10      raeburn  2259:                     }
1.14      raeburn  2260:                     if (($env{'form.crstype'} eq 'any') || 
1.10      raeburn  2261:                         ($env{'form.crstype'} eq 'official')) {
1.14      raeburn  2262:                         my $showinstcode;
                   2263:                         if ($type eq 'official') {
                   2264:                             $showinstcode = &unescape($instcode);
                   2265:                         } else {
                   2266:                             $showinstcode = &mt('Not applicable');
                   2267:                         }
                   2268:                         $output .= '<td>'.$showinstcode.'</td>';
1.10      raeburn  2269:                     }
                   2270:                     $output .= '<td>'.$showtime.'</td>'.
                   2271:                                &Apache::loncommon::end_data_table_row();
                   2272:                 }
                   2273:             }
                   2274:         }
                   2275:         $output .= &Apache::loncommon::end_data_table();
                   2276:     } else {
1.40      raeburn  2277:         if ($env{'form.crstype'} eq 'any') {
                   2278: $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>';
                   2279:         } elsif ($env{'form.crstype'} eq 'community') {
                   2280:             $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>';
                   2281:         } else {
                   2282:             $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>';
                   2283:         }
1.10      raeburn  2284:     }
                   2285:     $output .= '
1.30      raeburn  2286: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10      raeburn  2287:     return $output;
1.1       raeburn  2288: }
                   2289: 
1.16      raeburn  2290: sub print_cancel_request {
                   2291:     my ($dom,$cnum) = @_;
                   2292:     my $requestkey = $dom.'_'.$cnum;
                   2293:     my ($result,$output);
                   2294:     if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                   2295:         my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                   2296:                                                $env{'user.domain'},$env{'user.name'});
                   2297:         my $timestamp = $history{'reqtime'};
                   2298:         my $crstype = $history{'crstype'};
                   2299:         my $status = $history{'status'};
                   2300:         if (($status eq 'cancelled') || ($status eq 'created')) { 
                   2301:             if ($status eq 'cancelled') {
                   2302:                 $output = &mt('This request has already been cancelled.');
                   2303:             } elsif ($status eq 'created') {
                   2304:                 $output = &mt('This request has already been processed, and a course created.');
                   2305:             }
                   2306:             $output = &mt('No further action will be taken');
                   2307:         } elsif (ref($history{'details'}) eq 'HASH') {
1.37      raeburn  2308:             my ($types,$typename) = &Apache::loncommon::course_types();
1.16      raeburn  2309:             my $showtype = $crstype;
                   2310:             if (defined($typename->{$crstype})) {
                   2311:                 $showtype = $typename->{$crstype}; 
                   2312:             }
                   2313:             $output = '<p>'.&Apache::loncommon::start_data_table().
                   2314:                       &Apache::loncommon::start_data_table_header_row().
                   2315:                       '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
                   2316:                       '<th>'.&mt('Type').'</th>'.
                   2317:                       &Apache::loncommon::end_data_table_header_row().
                   2318:                       &Apache::loncommon::start_data_table_row().
                   2319:                       '<td>'.$history{details}{'cdescr'}.'</td><td>'.
                   2320:                       &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
                   2321:                       '<td>'.$showtype.'</td>'.
                   2322:                       &Apache::loncommon::end_data_table_row().
                   2323:                       &Apache::loncommon::end_data_table().
1.40      raeburn  2324:                       '<br /><div class="LC_warning">';
                   2325:             if ($crstype eq 'community') {
                   2326:                 $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
                   2327:             } else {
                   2328:                 $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
                   2329:             }
1.16      raeburn  2330:             $result = 'ok';
                   2331:         } else {
                   2332:             $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
                   2333:         }
                   2334:     } else {
                   2335:         $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
                   2336:     }
                   2337:     return ($result,$output);
                   2338: }
                   2339: 
                   2340: sub viewrequest_javascript {
                   2341:     my ($formname,$next) = @_;
                   2342:     return <<"ENDJS";
                   2343: 
                   2344: function chooseRequest(cdom,cnum) {
                   2345:     document.$formname.showdom.value = cdom;
                   2346:     document.$formname.cnum.value = cnum;
                   2347:     nextPage(document.$formname,'$next');
                   2348: }
                   2349: 
                   2350: ENDJS
                   2351: }
                   2352: 
                   2353: sub viewdetails_javascript {
                   2354:     my ($formname) = @_;
                   2355:     return << "ENDJS";
                   2356: 
                   2357: function nextPage(formname,nextstate) {
                   2358:     if (nextstate == "modify") { 
                   2359:         formname.state.value = "personnel";
                   2360:         formname.action.value = "new";
                   2361:     } else {
                   2362:         formname.state.value = nextstate;
                   2363:     }
                   2364:     formname.submit();
                   2365: }
                   2366: 
                   2367: function backPage(formname,prevstate) {
                   2368:     formname.state.value = prevstate;
                   2369:     formname.submit();
                   2370: }
                   2371: 
                   2372: ENDJS
                   2373: }
                   2374: 
                   2375: sub viewcancel_javascript {
1.68      bisitz   2376:     my $alert = &mt('Are you sure you want to cancel this request?').'\\n'.
                   2377:                 &mt('Your request will be removed.');
1.16      raeburn  2378:     return << "ENDJS";
                   2379: function nextPage(formname,nextstate) {
                   2380:     if (confirm('$alert')) {
                   2381:         formname.state.value = nextstate;
                   2382:         formname.submit();
                   2383:     }
                   2384:     return;
                   2385: }
                   2386: 
                   2387: ENDJS
                   2388: }
                   2389: 
1.1       raeburn  2390: sub print_request_logs {
1.73      raeburn  2391:     my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_;
1.48      raeburn  2392:     my $title;
                   2393:     if ($env{'form.crstype'} eq 'community') {
                   2394:         $title = 'Community Request Logs';
                   2395:     } elsif ($env{'form.crstype'} eq 'any') {
                   2396:         $title = 'Course/Community Request Logs';
                   2397:     } else {
                   2398:         $title = 'Course Request Logs';
                   2399:     }
                   2400:     $r->print(&header($title,$jscript,$loaditems).$crumb);
1.73      raeburn  2401:     if ($usetabs) {
                   2402:         &startContentScreen($r,'textbooklogs');
                   2403:     }
1.48      raeburn  2404:     my $formname = 'requestcrs';
                   2405:     $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
                   2406:               '<input type="hidden" name="action" value="log" />'."\n".
                   2407:               '<input type="hidden" name="state" value="display" />'."\n");
                   2408:     # set defaults
                   2409:     my $now = time();
                   2410:     my $defstart = $now - (7*24*3600); #7 days ago
                   2411:     my %defaults = (
                   2412:                      page                => '1',
                   2413:                      show                => '10',
                   2414:                      crstype             => 'any',
                   2415:                      status              => 'any',
                   2416:                      requested_before_date => $now,
                   2417:                      requested_after_date  => $defstart,
                   2418:                    );
                   2419:     my ($types,$typenames) = &Apache::loncommon::course_types();
                   2420:     my $more_records = 0;
                   2421:     my %curr;
                   2422:     foreach my $item ('show','page','crstype','status') {
                   2423:         $curr{$item} = $env{'form.'.$item};
                   2424:     }
                   2425:     $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
                   2426:     $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
                   2427:     foreach my $key (keys(%defaults)) {
                   2428:         if ($curr{$key} eq '') {
                   2429:             $curr{$key} = $defaults{$key};
                   2430:         }
                   2431:     }
                   2432:     my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
                   2433:     $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
                   2434:               &requestlog_display_filter($formname,\%curr));
1.49      raeburn  2435:     my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
1.48      raeburn  2436:     my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
                   2437:     my $showntablehdr = 0;
                   2438:     my $tablehdr = &Apache::loncommon::start_data_table().
                   2439:                    &Apache::loncommon::start_data_table_header_row().
                   2440:                    '<th>&nbsp;</th><th>'.&mt('Request Date').'</th>'.
                   2441:                    '<th>'.&mt('Description').'</th>';
                   2442:     if ($curr{'crstype'} eq 'any') {
                   2443:         $tablehdr .= '<th>'.&mt('Course Type').'</th>';
                   2444:     }
                   2445:     if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
                   2446:         $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
                   2447:     }
1.73      raeburn  2448:     my $showuniquecode;
                   2449:     my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
                   2450:     if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) {
                   2451:         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   2452:             if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
                   2453:                 if ($curr{'crstype'} eq 'any') {
                   2454:                     my @types = qw(official unofficial community textbook);
                   2455:                     foreach my $type (@types) {
                   2456:                         if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
                   2457:                             $showuniquecode = 1;
                   2458:                             last;
                   2459:                         }
                   2460:                     }
                   2461:                 } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) {
                   2462:                     $showuniquecode = 1;
                   2463:                 }
                   2464:             }
                   2465:         }
                   2466:     }
                   2467:     if ($showuniquecode) {
                   2468:         $tablehdr .= '<th>'.&mt('Unique Code').'</th>';    
                   2469:     }
1.48      raeburn  2470:     if ($curr{'status'} eq 'any') {
                   2471:         $tablehdr .= '<th>'.&mt('Status').'</th>';
                   2472:     } elsif ($curr{'status'} eq 'created') {
                   2473:         $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
                   2474:     } elsif ($curr{'status'} eq 'cancelled') {
                   2475:         $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
                   2476:     } elsif ($curr{'status'} eq 'rejected') {
                   2477:         $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
                   2478:     }
                   2479:     $tablehdr .= &Apache::loncommon::end_data_table_header_row();
                   2480:     my ($minshown,$maxshown);
                   2481:     $minshown = 1;
                   2482:     my $count = 0;
                   2483:     if ($curr{'show'} ne &mt('all')) {
                   2484:         $maxshown = $curr{'page'} * $curr{'show'};
                   2485:         if ($curr{'page'} > 1) {
                   2486:             $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
                   2487:         }
                   2488:     }
                   2489:     my $norecords;
                   2490:     if (@sortedtimes > 0) {
                   2491:         foreach my $item (@sortedtimes) {
                   2492:             if ($curr{'show'} ne &mt('all')) {
                   2493:                 if ($count >= $curr{'page'} * $curr{'show'}) {
                   2494:                     $more_records = 1;
                   2495:                     last;
                   2496:                 }
                   2497:             }
                   2498:             $count ++;
                   2499:             next if ($count < $minshown);
                   2500:             if (!$showntablehdr) {
                   2501:                 $r->print($tablehdr);
                   2502:                 $showntablehdr = 1;
                   2503:             }
                   2504:             my $showtime = &Apache::lonlocal::locallocaltime($item);
                   2505:             if (ref($queue_by_date{$item}) eq 'ARRAY') {
                   2506:                 foreach my $request (sort(@{$queue_by_date{$item}})) {
1.73      raeburn  2507:                     my ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request);
1.48      raeburn  2508:                     my ($cdom,$cnum) = split('_',$key);
                   2509:                     my $output = &Apache::loncommon::start_data_table_row().
                   2510:      '<td>'.$count.'</td>'.
                   2511:      '<td>'.$showtime.'</td>'.
                   2512:      '<td>'.&unescape($desc).'</td>';
                   2513:                     if ($curr{'crstype'} eq 'any') {
                   2514:                         my $typename;
                   2515:                         if (ref($typenames) eq 'HASH') {
                   2516:                             $typename = &mt($typenames->{$crstype});
                   2517:                         }
                   2518:                         if ($typename eq '') {
                   2519:                             $typename = &mt('Unknown type');
                   2520:                         }
                   2521:                         $output .= '<td>'.$typename.'</td>';
                   2522:                     }
                   2523:                     if (($curr{'crstype'} eq 'any') ||
                   2524:                         ($curr{'crstype'} eq 'official')) {
                   2525:                         my $showinstcode;
                   2526:                         if ($crstype eq 'official') {
                   2527:                             $showinstcode = &unescape($instcode);
                   2528:                         } else {
                   2529:                             $showinstcode = &mt('Not applicable');
                   2530:                         }
                   2531:                         $output .= '<td>'.$showinstcode.'</td>';
                   2532:                     }
1.73      raeburn  2533:                     if ($showuniquecode) {
                   2534:                         if ($status eq 'created') {
                   2535:                             $output .= '<td>'.$uniquecode.'</td>';
                   2536:                         } else {
                   2537:                             $output .= '<td>'.&mt('Not applicable').'</td>';
                   2538:                         }    
                   2539:                     }
1.48      raeburn  2540:                     if ($curr{'status'} eq 'any') {
                   2541:                         my $statusname = &mt('Unknown status');
                   2542:                         if (ref($statusnames) eq 'HASH') {
                   2543:                             if ($statusnames->{$status} ne '') {
                   2544:                                 $statusname = $statusnames->{$status};
                   2545:                             }
                   2546:                         }
                   2547:                         if (($status eq 'created') || ($status eq 'cancelled') ||
                   2548:                             ($status eq 'rejected')) {
                   2549:                             $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
                   2550:                         }
                   2551:                         $output .= '<td>'.$statusname.'</td>';
                   2552:                     } elsif (($status eq 'created') || ($status eq 'cancelled') ||
                   2553:                              ($status eq 'rejected')) {
                   2554:                          $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
                   2555:                     }
                   2556:                     $output .= &Apache::loncommon::end_data_table_row();
                   2557:                     $r->print($output);
                   2558:                 }
                   2559:             }
                   2560:         }
                   2561:         if ($showntablehdr) {  
                   2562:             $r->print(&Apache::loncommon::end_data_table());
                   2563:             if (($curr{'page'} > 1) || ($more_records)) {
                   2564:                 $r->print('<table><tr>');
                   2565:                 if ($curr{'page'} > 1) {
                   2566:                     $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
                   2567:                 }
                   2568:                 if ($more_records) {
                   2569:                     $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
                   2570:                 }
                   2571:                 $r->print('</tr></table>');
                   2572:                 $r->print(<<"ENDSCRIPT");
                   2573: <script type="text/javascript">
                   2574: // <![CDATA[
                   2575: function chgPage(caller) {
                   2576:     if (caller == 'previous') {
                   2577:         document.$formname.page.value --;
                   2578:     }
                   2579:     if (caller == 'next') {
                   2580:         document.$formname.page.value ++;
                   2581:     }
                   2582:     document.$formname.submit();
1.1       raeburn  2583:     return;
                   2584: }
1.48      raeburn  2585: // ]]>
                   2586: </script>
                   2587: ENDSCRIPT
                   2588:             }
                   2589:         } else {
                   2590:             $norecords = 1;
                   2591:         }
                   2592:     } else {
                   2593:         $norecords = 1;
                   2594:     }
                   2595:     if ($norecords) {
                   2596:         $r->print('<p class="LC_info">'.
                   2597:                   &mt('There are no records to display').
                   2598:                   '</p>');
                   2599:     }
1.73      raeburn  2600:     if ($usetabs) {
                   2601:         $r->print('<input type="hidden" name="tabs" value="on" />');
                   2602:     }
                   2603:     $r->print('</form>');
                   2604:     if ($usetabs) {
                   2605:         &endContentScreen($r);
                   2606:     }
                   2607:     $r->print(&Apache::loncommon::end_page());
1.48      raeburn  2608:     return;
                   2609: }
                   2610: 
                   2611: sub reqstatus_names {
                   2612:     my ($crstype) = @_;
                   2613:     my @statuses = qw(created approval pending rejected cancelled);
                   2614:     my %statusnames =
                   2615:             &Apache::lonlocal::texthash (
1.50      raeburn  2616:                         created   => 'Created',
1.48      raeburn  2617:                         approval  => 'Queued pending approval',
                   2618:                         pending   => 'Queued pending validation',
                   2619:                         rejected  => 'Request rejected',
                   2620:                         cancelled => 'Request cancelled',
                   2621:             );
1.69      raeburn  2622:     if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) {
1.48      raeburn  2623:         $statusnames{'created'} = &mt('Course created');
                   2624:     } elsif ($crstype eq 'community') {
                   2625:         $statusnames{'created'} = &mt('Community created');
                   2626:     }
                   2627:     return (\@statuses,\%statusnames);
                   2628: }
                   2629: 
                   2630: sub requestlog_display_filter {
                   2631:     my ($formname,$curr) = @_;
                   2632:     my $nolink = 1;
                   2633:     my $output = '<table><tr><td valign="top">'.
                   2634:                  '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
                   2635:                  &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
                   2636:                                               (&mt('all'),5,10,20,50,100,1000,10000)).
                   2637:                  '</td><td>&nbsp;&nbsp;</td>';
                   2638:     my $startform =
                   2639:         &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
                   2640:                                             $curr->{'requested_after_date'},undef,
                   2641:                                             undef,undef,undef,undef,undef,undef,$nolink);
                   2642:     my $endform =
                   2643:         &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
                   2644:                                             $curr->{'requested_before_date'},undef,
                   2645:                                             undef,undef,undef,undef,undef,undef,$nolink);
                   2646:     $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
                   2647:                '<table><tr><td>'.&mt('After:').
                   2648:                '</td><td>'.$startform.'</td></tr>'.
                   2649:                '<tr><td>'.&mt('Before:').'</td>'.
                   2650:                '<td>'.$endform.'</td></tr></table>'.
                   2651:                '</td>'.
                   2652:                '<td>&nbsp;&nbsp;</td>';
                   2653:     my ($types,$typenames) = &Apache::loncommon::course_types();
                   2654:     if (ref($types) eq 'ARRAY') {
                   2655:         if (@{$types} > 1) {
                   2656:             $output .= '<td valign="top"><b>'.
                   2657:                        &mt('Course Type:').'</b><br /><select name="crstype">';
                   2658:             my $selstr = '';
                   2659:             if ($curr->{'crstype'} eq 'any') {
                   2660:                 $selstr = ' selected="selected"';
                   2661:             }
                   2662:             $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
                   2663:             foreach my $crstype (@{$types}) {
                   2664:                 my $selstr = '';
                   2665:                 if ($curr->{'crstype'} eq $crstype) {
                   2666:                     $selstr = ' selected="selected"';
                   2667:                 }
                   2668:                 my $typename = $crstype;
                   2669:                 if (ref($typenames) eq 'HASH') {
                   2670:                     if ($typenames->{$crstype} ne '') {
                   2671:                         $typename = $typenames->{$crstype};
                   2672:                     }
                   2673:                 }
                   2674:                 $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
                   2675:             }
                   2676:             $output .= '</select></td>';
                   2677:         }
                   2678:     }
                   2679:     my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
                   2680:     if (ref($statuses) eq 'ARRAY') {
                   2681:         if (@{$statuses} > 1) {
                   2682:             $output .= '<td valign="top"><b>'.
                   2683:                        &mt('Request Status:').'</b><br /><select name="status">';
                   2684:             my $selstr = '';
                   2685:             if ($curr->{'status'} eq 'any') {
                   2686:                 $selstr = ' selected="selected"';
                   2687:             }
                   2688:             $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
                   2689:             foreach my $status (@{$statuses}) {
                   2690:                 my $selstr = '';
                   2691:                 if ($curr->{'status'} eq $status) {
                   2692:                     $selstr = ' selected="selected"';
                   2693:                 }
                   2694:                 my $statusname = $status;
                   2695:                 if (ref($statusnames) eq 'HASH') {
                   2696:                     if ($statusnames->{$status} ne '') {
                   2697:                         $statusname = $statusnames->{$status};
                   2698:                     }
                   2699:                 }
                   2700:                 $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
                   2701:             }
                   2702:             $output .= '</select></td>';
                   2703:         }
                   2704:     }
                   2705:     $output .= '</tr></table>';
                   2706: 
                   2707:     # Update Display button
                   2708:     $output .= '<p>'.
                   2709:                '<input type="submit" value="'.&mt('Update Display').'" />'.
                   2710:                '</p><hr />';
                   2711:     return $output;
                   2712: }
1.1       raeburn  2713: 
                   2714: sub print_review {
1.30      raeburn  2715:     my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
1.66      raeburn  2716:         $disallowed,$disallowmsg,$instcredits) = @_;
1.37      raeburn  2717:     my ($types,$typename) = &Apache::loncommon::course_types();
1.4       raeburn  2718:     my ($owner,$ownername,$owneremail);
1.26      raeburn  2719:     if ($uname eq '' || $udom eq '') {
                   2720:         $uname = $env{'user.name'};
                   2721:         $udom = $env{'user.domain'};
                   2722:     }
                   2723:     $owner = $uname.':'.$udom;
                   2724:     $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
                   2725:     my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4       raeburn  2726:     foreach my $email ('permanentemail','critnotification','notification') {
                   2727:         $owneremail = $emails{$email};
                   2728:         last if ($owneremail ne '');
                   2729:     }
                   2730:     my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
                   2731:         $section_headers,$section_values,$personnel_headers,$personnel_values);
                   2732: 
                   2733:     $crstypename = $env{'form.crstype'};
                   2734:     if (ref($typename) eq 'HASH') {
                   2735:         unless ($typename->{$env{'form.crstype'}} eq '') {
1.35      raeburn  2736:             $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4       raeburn  2737:         }
                   2738:     }
1.16      raeburn  2739:     my $category = 'Course';
                   2740:     if ($env{'form.crstype'} eq 'community') {
                   2741:         $category = 'Community';
                   2742:     }
1.4       raeburn  2743: 
                   2744:     $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
                   2745:     $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
                   2746: 
1.16      raeburn  2747:     my $enrollrow_title = &mt('Default Access Dates').'<br />'.
                   2748:                           '('.&Apache::lonnet::plaintext('st',$category).')';
1.4       raeburn  2749:     if ($env{'form.crstype'} eq 'official') {
                   2750:         if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
                   2751:             foreach my $title (@{$codetitles}) {
                   2752:                 if ($env{'form.instcode_'.$title} ne '') {
                   2753:                     $inst_headers .= '<th>'.$title.'</th>';
                   2754:                     my $longitem = $env{'form.instcode_'.$title};
                   2755:                     if (ref($cat_titles->{$title}) eq 'HASH') {
                   2756:                         if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
                   2757:                             $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
                   2758:                         }
                   2759:                     }
                   2760:                     $inst_values .= '<td>'.$longitem.'</td>';
                   2761:                 }
                   2762:             }
                   2763:         }
1.66      raeburn  2764:         $inst_headers .= '<th>'.&mt('Credits').'</th>';
                   2765:         if ($instcredits) {
                   2766:             $inst_values .= '<td>'.$instcredits.'</td>';
                   2767:         } else {
                   2768:             $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
                   2769:         }
1.4       raeburn  2770:         if (&Apache::lonnet::auto_run('',$dom)) {
1.16      raeburn  2771:             $enrollrow_title = &mt('Enrollment');
1.4       raeburn  2772:             $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
                   2773:                               '<th>'.&mt('Automatic Drops').'</th>'.
                   2774:                               '<th>'.&mt('Enrollment Starts').'</th>'.
                   2775:                               '<th>'.&mt('Enrollment Ends').'</th>';
                   2776:             $section_headers = '<th>'.&mt('Sections').'</th>'.
                   2777:                                '<th>'.&mt('Crosslistings').'</th>';
                   2778: 
1.13      raeburn  2779:             my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4       raeburn  2780:             my @autoroster = (&mt('No'),&mt('Yes'));
                   2781:             $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
                   2782:                              '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13      raeburn  2783:                              '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
                   2784:                              '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6       raeburn  2785:             $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
                   2786:                               &mt('Institutional section').'</th>'.
                   2787:                               '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5       raeburn  2788:             my $secinfo;
1.4       raeburn  2789:             if ($env{'form.sectotal'} > 0) {
                   2790:                 for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   2791:                     if ($env{'form.sec_'.$i}) {
1.5       raeburn  2792:                         $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4       raeburn  2793:                         if ($env{'form.loncapasec_'.$i} ne '') {
1.5       raeburn  2794:                             $secinfo .= $env{'form.loncapasec_'.$i};
                   2795:                         } else {
                   2796:                             $secinfo .= &mt('None');
1.4       raeburn  2797:                         }
1.5       raeburn  2798:                         $secinfo .= '</td></tr>';
1.4       raeburn  2799:                     }
                   2800:                 }
                   2801:             }
1.6       raeburn  2802:             if ($secinfo eq '') {
                   2803:                 $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5       raeburn  2804:             }
1.6       raeburn  2805:             $section_values .= $secinfo.'</table></td><td>'.
                   2806:                                '<table class="LC_innerpickbox"><tr><th>'.
                   2807:                                &mt('Institutional course/section').'</th>'.
                   2808:                                '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5       raeburn  2809:             my $xlistinfo;
1.24      raeburn  2810:             my $crosslisttotal = $env{'form.crosslisttotal'};
                   2811:             if (!$crosslisttotal) {
                   2812:                 $crosslisttotal = 1;
                   2813:             }
                   2814:             for (my $i=0; $i<$crosslisttotal; $i++) {
                   2815:                 if ($env{'form.crosslist_'.$i}) {
                   2816:                     $xlistinfo .= '<tr><td>';
                   2817:                     if (ref($code_order) eq 'ARRAY') {
                   2818:                         if (@{$code_order} > 0) {
                   2819:                             foreach my $item (@{$code_order}) {
                   2820:                                 $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4       raeburn  2821:                             }
                   2822:                         }
                   2823:                     }
1.24      raeburn  2824:                     $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
                   2825:                     if ($env{'form.crosslist_'.$i.'_lcsec'}) {
                   2826:                         $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
                   2827:                     } else {
                   2828:                         $xlistinfo .= &mt('None');
                   2829:                     }
                   2830:                     $xlistinfo .= '</td></tr>';
1.4       raeburn  2831:                 }
                   2832:             }
1.6       raeburn  2833:             if ($xlistinfo eq '') {
                   2834:                 $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5       raeburn  2835:             }
1.24      raeburn  2836:             $section_values .= $xlistinfo;
1.4       raeburn  2837:         }
1.24      raeburn  2838:         $section_values .= '</table></td>';
1.69      raeburn  2839:     } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66      raeburn  2840:         $inst_headers .= '<th>'.&mt('Credits').'</th>';
                   2841:         $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
1.4       raeburn  2842:     }
                   2843: 
                   2844:     my %ctxt = &clone_text();
                   2845:     $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.45      raeburn  2846:     if (($env{'form.cloning'}) &&
                   2847:         ($env{'form.clonecrs'} =~ /^$match_name$/) && 
1.13      raeburn  2848:         ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.56      raeburn  2849:         my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
                   2850:                            $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
1.39      raeburn  2851:                            $env{'form.crstype'});
1.15      raeburn  2852:         if ($canclone) {
                   2853:             my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
                   2854:                               $env{'form.clonecrs'},('description','internal.coursecode'));
                   2855:             if (keys(%courseenv) > 0) {
                   2856:                 $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
                   2857:                 $inst_values .= '<td>'.$courseenv{'description'}.'&nbsp;';
                   2858:                 my $cloneinst = $courseenv{'internal.coursecode'};
                   2859:                 if ($cloneinst ne '') {
1.18      raeburn  2860:                     $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15      raeburn  2861:                 } else {
1.18      raeburn  2862:                     $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15      raeburn  2863:                 }
                   2864:                 $inst_values .= '</td><td>';
                   2865:                 if ($env{'form.datemode'} eq 'preserve') {
1.16      raeburn  2866:                     $inst_values .= $ctxt{'prd'}; 
1.15      raeburn  2867:                 } elsif ($env{'form.datemode'} eq 'shift') {
                   2868:                     $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
                   2869:                 } else {
                   2870:                     $inst_values .= $ctxt{'ncd'};
                   2871:                 }
                   2872:                 $inst_values .= '</td>';
                   2873:              } else {
                   2874:                  $inst_values .= '<td>'.&mt('Unknown').'</td>';
                   2875:              }
                   2876:          } else {
                   2877:              $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
                   2878:          }
1.4       raeburn  2879:     } else {
                   2880:         $inst_values .= '<td>'.&mt('None').'</td>';
                   2881:     }
                   2882:     $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
                   2883:                        '<th>'.&mt('Access Ends').'</th>';
1.13      raeburn  2884:     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
                   2885:     $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
                   2886:     if ($accessend == 0) {
1.4       raeburn  2887:         $enroll_values .= '<td>'.&mt('No end date').'</td>';
                   2888:     } else {
1.13      raeburn  2889:         $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4       raeburn  2890:     }
                   2891: 
                   2892:     my $container = 'Course';
1.41      raeburn  2893:     my $ccrole = 'cc';
1.4       raeburn  2894:     if ($env{'form.crstype'} eq 'community') {
                   2895:         $container = 'Community';
1.41      raeburn  2896:         $ccrole = 'co';
1.4       raeburn  2897:     }
                   2898: 
                   2899:     $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
                   2900:                          '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
                   2901:                          '</th>';
1.41      raeburn  2902: 
1.4       raeburn  2903:     $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41      raeburn  2904:                          '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4       raeburn  2905:                          '<td>'.&mt('None').'</td></tr>';
                   2906:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   2907:         if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30      raeburn  2908:             if (ref($disallowed) eq 'ARRAY') {
                   2909:                 next if (grep(/^$i$/,@{$disallowed}));
                   2910:             } 
1.31      raeburn  2911:             my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
                   2912:             my @allsecs;
                   2913:             foreach my $sec (@officialsecs) {
                   2914:                 next unless ($sec =~ /\w/);
                   2915:                 next if ($sec =~ /\W/);
                   2916:                 next if ($sec eq 'none');
                   2917:                 push(@allsecs,$sec);
                   2918:             }
1.14      raeburn  2919:             my $newsec = $env{'form.person_'.$i.'_newsec'};
                   2920:             $newsec =~ s/^\s+//;
                   2921:             $newsec =~s/\s+$//;
1.31      raeburn  2922:             my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14      raeburn  2923:             foreach my $sec (@newsecs) {
1.31      raeburn  2924:                 next unless ($sec =~ /\w/); 
1.14      raeburn  2925:                 next if ($sec =~ /\W/);
1.31      raeburn  2926:                 next if ($sec eq 'none');
1.14      raeburn  2927:                 if ($sec ne '') {
                   2928:                     unless (grep(/^\Q$sec\E$/,@allsecs)) {
                   2929:                         push(@allsecs,$sec); 
                   2930:                     }
                   2931:                 }
                   2932:             }
1.24      raeburn  2933:             my $showsec;
1.14      raeburn  2934:             if (@allsecs) {
                   2935:                 $showsec = join(', ',@allsecs);
                   2936:             }
1.24      raeburn  2937:             if ($showsec eq '') {
                   2938:                 $showsec = &mt('None');
                   2939:             }
1.41      raeburn  2940:             if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24      raeburn  2941:                 $showsec = &mt('None');
                   2942:             }
1.28      raeburn  2943:             my $role = $env{'form.person_'.$i.'_role'}; 
1.4       raeburn  2944:             $personnel_values .= 
1.13      raeburn  2945:                 '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
                   2946:                 $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4       raeburn  2947:                 '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
                   2948:                 $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28      raeburn  2949:                 '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14      raeburn  2950:                 '<td>'.$showsec.'</td></tr>';
1.4       raeburn  2951:         }
                   2952:     }
1.30      raeburn  2953:     my $output;
                   2954:     if (ref($disallowed) eq 'ARRAY') {
                   2955:         if (@{$disallowed} > 0) {
                   2956:             if (ref($disallowmsg) eq 'HASH') {
                   2957:                 $output = '<p class="LC_warning">'.
                   2958:                           &mt('Not all requested personnel could be included.').'<ul>'; 
                   2959:                 foreach my $item (@{$disallowed}) {
                   2960:                     $output .= '<li>'.$disallowmsg->{$item}.'</li>';
                   2961:                 }
                   2962:                 $output .= '</ul></p>';
                   2963:             }
                   2964:         }
                   2965:     }
                   2966:     $output .=    '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4       raeburn  2967:                   &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6       raeburn  2968:                   '<table class="LC_innerpickbox"><tr>'.
1.4       raeburn  2969:                   '<th>'.&mt('Name').'</th>'.
                   2970:                   '<th>'.&mt('Username:Domain').'</th>'.
                   2971:                   '<th>'.&mt('E-mail address').'</th>'.
                   2972:                   '</tr><tr>'."\n".
                   2973:                   '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
                   2974:                   '<td>'.$owneremail.'</td>'.
                   2975:                   '</tr></table>'."\n".
                   2976:                   &Apache::lonhtmlcommon::row_closure().
1.5       raeburn  2977:                   &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4       raeburn  2978:                   '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
                   2979:                   '<tr>'.$inst_values.'</tr></table>'."\n".
                   2980:                   &Apache::lonhtmlcommon::row_closure().
1.16      raeburn  2981:                   &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4       raeburn  2982:                   '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
                   2983:                   '<tr>'.$enroll_values.'</tr></table>'."\n".
                   2984:                   &Apache::lonhtmlcommon::row_closure();
                   2985:     if ($section_headers ne '') {
                   2986:         $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
                   2987:                    '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
                   2988:                    '<tr>'.$section_values.'</tr></table>'."\n".
                   2989:                    &Apache::lonhtmlcommon::row_closure();
                   2990:     }
                   2991:     $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
                   2992:                '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
                   2993:                $personnel_values.'</table>'."\n".
                   2994:                &Apache::lonhtmlcommon::row_closure(1).
1.26      raeburn  2995:                &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4       raeburn  2996:     return $output;
                   2997: }
                   2998: 
                   2999: sub dates_from_form {
                   3000:     my ($startname,$endname) = @_;
                   3001:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
                   3002:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13      raeburn  3003:     if ($endname eq 'accessend') {
1.4       raeburn  3004:         if (exists($env{'form.no_end_date'}) ) {
                   3005:             $enddate = 0;
                   3006:         }
                   3007:     }
                   3008:     return ($startdate,$enddate);
1.1       raeburn  3009: }
                   3010: 
                   3011: sub courseinfo_form {
1.36      raeburn  3012:     my ($dom,$formname,$crstype,$next,$description) = @_;
1.32      raeburn  3013:     my %lt = &Apache::lonlocal::texthash(
                   3014:                 official => 'You must provide a (brief) course description.',
                   3015:                 community => 'You must provide a (brief) community description.'
                   3016:              );
                   3017:     $lt{'unofficial'} = $lt{'official'};
1.69      raeburn  3018:     $lt{'textbook'} = $lt{'official'};
1.15      raeburn  3019:     my $js_validate = <<"ENDJS";
                   3020: <script type="text/javascript">
                   3021: // <![CDATA['
                   3022: 
                   3023: function validateForm() {
                   3024:     if ((document.$formname.cdescr.value == "")  || (document.$formname.cdescr.value == "undefined")) {
1.32      raeburn  3025:         alert('$lt{$crstype}');
1.15      raeburn  3026:         return;
                   3027:     }
                   3028:     nextPage(document.$formname,'$next');
                   3029: }
1.45      raeburn  3030: 
                   3031: function toggleCloning() {
                   3032:     var willclone;
                   3033:     if (document.$formname.cloning.length > 1) {
                   3034:         for (var i=0; i<document.$formname.cloning.length; i++) {
                   3035:             if (document.$formname.cloning[i].checked) {
                   3036:                 willclone = document.$formname.cloning[i].value;
                   3037:             }
                   3038:         }
                   3039:     }
                   3040:     if (willclone == 1) {
                   3041:         document.getElementById('cloneoptions').style.display="block";
                   3042:     } else {
                   3043:         document.getElementById('cloneoptions').style.display="none";
                   3044:         document.$formname.clonecrs.value = '';
                   3045:     }
                   3046: }
                   3047: 
1.15      raeburn  3048: // ]]
                   3049: </script>
                   3050: 
                   3051: ENDJS
1.27      raeburn  3052:     my $title = &mt('Brief Course Description');
1.40      raeburn  3053:     my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27      raeburn  3054:     if ($crstype eq 'community') {
                   3055:         $title = &mt('Brief Community Description');
1.40      raeburn  3056:         $clonetitle = &mt('Clone content and settings from an existing community?');
1.27      raeburn  3057:     }
1.45      raeburn  3058:     my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27      raeburn  3059:                   &Apache::lonhtmlcommon::row_headline().
1.34      raeburn  3060:                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').'&nbsp;'.$title.'</h3>'.
1.27      raeburn  3061:                   &Apache::lonhtmlcommon::row_closure(1).
                   3062:                   &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36      raeburn  3063:                  '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13      raeburn  3064:     my ($home_server_pick,$numlib) =
                   3065:         &Apache::loncommon::home_server_form_item($dom,'chome',
                   3066:                                                   'default','hide');
                   3067:     if ($numlib > 1) {
                   3068:         $output .= &Apache::lonhtmlcommon::row_closure().
1.16      raeburn  3069:                    &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13      raeburn  3070:     }
                   3071:     $output .= $home_server_pick.
1.27      raeburn  3072:                &Apache::lonhtmlcommon::row_closure().
                   3073:                &Apache::lonhtmlcommon::row_headline().
1.45      raeburn  3074:                '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').'&nbsp;'.$clonetitle.
1.46      wenzelju 3075:                &Apache::lonhtmlcommon::row_closure(1).
                   3076:                &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
1.45      raeburn  3077:                '<label><input type="radio" name="cloning" value="1" '.
                   3078:                'onclick="javascript:toggleCloning()" />'.
                   3079:                &mt('Yes').('&nbsp;'x2).'</label><label>'.
1.49      raeburn  3080:                '<input type="radio" name="cloning" value="0" checked="checked" '.
1.45      raeburn  3081:                'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
                   3082:                '</h3>'.
1.13      raeburn  3083:                &Apache::lonhtmlcommon::row_closure(1).
1.45      raeburn  3084:                &Apache::lonhtmlcommon::row_headline().
                   3085:                '<div id="cloneoptions" style="display: none" >'.
                   3086:                &Apache::lonhtmlcommon::start_pick_box().
1.27      raeburn  3087:                &clone_form($dom,$formname,$crstype).
1.45      raeburn  3088:                &Apache::lonhtmlcommon::end_pick_box().'</div>'.
                   3089:                &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1       raeburn  3090:     return $output;
                   3091: }
                   3092: 
                   3093: sub clone_form {
                   3094:     my ($dom,$formname,$crstype) = @_;
                   3095:     my $type = 'Course';
                   3096:     if ($crstype eq 'community') {
                   3097:         $type = 'Community';
                   3098:     }
1.4       raeburn  3099:     my %lt = &clone_text();
1.2       raeburn  3100:     my $output .= 
1.53      raeburn  3101:         &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
                   3102:         &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
                   3103:         &Apache::lonhtmlcommon::row_closure(1).
1.2       raeburn  3104:         &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.53      raeburn  3105:         '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
                   3106:         '</label>&nbsp;'.
                   3107:         &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
                   3108:         &Apache::lonhtmlcommon::row_closure(1).
1.2       raeburn  3109:         &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
                   3110:         '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
                   3111:         '</label><br /><label>'.
                   3112:         '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
                   3113:         '</label><br /><label>'.
                   3114:         '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
                   3115:         $lt{'shd'}.'</label>'.
                   3116:         '<input type="text" size="5" name="dateshift" value="365" />'.
1.27      raeburn  3117:         &Apache::lonhtmlcommon::row_closure(1);
1.1       raeburn  3118:     return $output;
                   3119: }
                   3120: 
1.16      raeburn  3121: sub clone_text {
1.4       raeburn  3122:     return &Apache::lonlocal::texthash(
                   3123:                'cid'  => 'Course ID',
                   3124:                'dmn'  => 'Domain',
                   3125:                'dsh'  => 'Date Shift',
                   3126:                'ncd'  => 'Do not clone date parameters',
                   3127:                'prd'  => 'Clone date parameters as-is',
                   3128:                'shd'  => 'Shift date parameters by number of days',
                   3129:         );
                   3130: }
                   3131: 
1.1       raeburn  3132: sub coursecode_form {
1.2       raeburn  3133:     my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1       raeburn  3134:     my $output;
1.46      wenzelju 3135:     my %rowtitle = &Apache::lonlocal::texthash (
1.2       raeburn  3136:                     instcode  => 'Course Category',
                   3137:                     crosslist => 'Cross Listed Course',
                   3138:                    );
1.34      raeburn  3139:     my %helpitem = ( 
                   3140:                      instcode => 'Course_Request_Category',
                   3141:                    );
1.1       raeburn  3142:     if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
                   3143:         (ref($cat_order))) {
1.2       raeburn  3144:         my ($sel,$instsec,$lcsec);
                   3145:         $sel = $context;
                   3146:         if ($context eq 'crosslist') {
                   3147:             $sel .= '_'.$num;
                   3148:             $instsec = &mt('Institutional section').'<br />'.
                   3149:                        '<input type="text" size="10" name="'.$sel.'_instsec" />';
                   3150:             $lcsec = &mt('LON-CAPA section').'<br />'.
                   3151:                      '<input type="text" size="10" name="'.$sel.'_lcsec" />';
                   3152:         }
1.1       raeburn  3153:         if (@{$codetitles} > 0) {
                   3154:             my $lastitem = pop(@{$codetitles});
1.2       raeburn  3155:             my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                            $lastitem.'" />';
1.1       raeburn  3156:             if (@{$codetitles} > 0) {
1.61      raeburn  3157:                 my $helplink;
                   3158:                 if (defined($helpitem{$context})) {
                   3159:                     $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).'&nbsp;';
                   3160:                 }
                   3161:                 $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
1.2       raeburn  3162:                           '<table><tr>';
1.1       raeburn  3163:                 if ($context eq 'crosslist') {
1.2       raeburn  3164:                     $output .= '<td>'.&mt('Include?').'<br />'.
                   3165:                                '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1       raeburn  3166:                 }
                   3167:                 foreach my $title (@{$codetitles}) {
                   3168:                     if (ref($cat_order->{$title}) eq 'ARRAY') {
                   3169:                         if (@{$cat_order->{$title}} > 0) {
                   3170:                             $output .= '<td align="center">'.$title.'<br />'."\n".
                   3171:                                        '<select name="'.$sel.'_'.$title.'">'."\n".
                   3172:                                        ' <option value="" selected="selected">'.
                   3173:                                        &mt('Select').'</option>'."\n";
                   3174:                             foreach my $item (@{$cat_order->{$title}}) {
                   3175:                                 my $longitem = $item;
                   3176:                                 if (ref($cat_titles->{$title}) eq 'HASH') {
                   3177:                                     if ($cat_titles->{$title}{$item} ne '') {
                   3178:                                         $longitem = $cat_titles->{$title}{$item};
                   3179:                                     }
                   3180:                                 }
                   3181:                                 $output .= '<option value="'.$item.'">'.$longitem.
                   3182:                                            '</option>'."\n";
                   3183:                             }
                   3184:                         }
                   3185:                         $output .= '</select></td>'."\n";
                   3186:                     }
                   3187:                 }
                   3188:                 if ($context eq 'crosslist') {
                   3189:                     $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2       raeburn  3190:                                $lastinput.'</td><td align="center">'.$instsec.'</td>'.
                   3191:                                '<td align="center">'.$lcsec.'</td></tr></table>';
1.1       raeburn  3192:                 } else {
                   3193:                     $output .= '</tr></table>'.
                   3194:                                &Apache::lonhtmlcommon::row_closure().
                   3195:                                &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
                   3196:                                $lastinput;
                   3197:                 }
                   3198:             } else {
                   3199:                 if ($context eq 'crosslist') {
                   3200:                     $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2       raeburn  3201:                                '<table><tr>'.
                   3202:                                '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
                   3203:                                '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
                   3204:                                '</tr></table>';
1.1       raeburn  3205:                 } else { 
                   3206:                     $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
                   3207:                                $lastinput;
                   3208:                 }
                   3209:             }
1.2       raeburn  3210:             $output .=  &Apache::lonhtmlcommon::row_closure(1);
                   3211:             push(@$codetitles,$lastitem);    
                   3212:         } elsif ($context eq 'crosslist') {
                   3213:             $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
                   3214:                        '<table><tr><td align="center">'.
                   3215:                        '<span class="LC_nobreak">'.&mt('Include?').
                   3216:                        '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
                   3217:                        '</td><td align="center">'.&mt('Institutional ID').'<br />'.
                   3218:                        '<input type="text" size="10" name="'.$sel.'_instsec" />'.
                   3219:                        '</td><td align="center">'.$lcsec.'</td></tr></table>'.
                   3220:                        &Apache::lonhtmlcommon::row_closure(1);
1.1       raeburn  3221:         }
                   3222:     }
                   3223:     return $output;
                   3224: }
                   3225: 
1.61      raeburn  3226: sub sections_form {
                   3227:     my ($dom,$instcode,$num) = @_;
                   3228:     my $rowtitle;
                   3229:     if ($instcode eq '') {
                   3230:         $rowtitle = &mt('Sections');
                   3231:     } else {
                   3232:         $rowtitle = &mt('Sections of [_1]',$instcode);
                   3233:     }
                   3234:     return &Apache::lonhtmlcommon::row_title($rowtitle).
                   3235:            '<table><tr><td align="center">'.
                   3236:            '<span class="LC_nobreak">'.&mt('Include?').
                   3237:            '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
                   3238:            '</td><td align="center">'.&mt('Institutional section').'<br />'.
                   3239:            '<input type="text" size="10" name="secnum_'.$num.'" />'.
                   3240:            '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
                   3241:            '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
                   3242:            '</td></tr></table>'.
                   3243:            &Apache::lonhtmlcommon::row_closure(1);
                   3244: }
                   3245: 
1.1       raeburn  3246: sub get_course_dom {
                   3247:     my $codedom = &Apache::lonnet::default_login_domain();
1.19      raeburn  3248:     if ($env{'form.showdom'} ne '') {
                   3249:         if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
                   3250:             return $env{'form.showdom'};
                   3251:         }
                   3252:     }
1.1       raeburn  3253:     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37      raeburn  3254:         my ($types,$typename) = &Apache::loncommon::course_types();
1.19      raeburn  3255:         if (ref($types) eq 'ARRAY') {
                   3256:             foreach my $type (@{$types}) {
                   3257:                 if (&Apache::lonnet::usertools_access($env{'user.name'},
                   3258:                                                       $env{'user.domain'},$type,
                   3259:                                                       undef,'requestcourses')) {
                   3260:                     return $env{'user.domain'};
                   3261:                 }
                   3262:             }
                   3263:             my @possible_doms;
                   3264:             foreach my $type (@{$types}) {
                   3265:                 my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
                   3266:                 if ($dom_str ne '') {
                   3267:                     my @domains = split(',',$dom_str);
                   3268:                     foreach my $entry (@domains) {
                   3269:                         my ($extdom,$extopt) = split(':',$entry);
                   3270:                         if ($extdom eq $env{'request.role.domain'}) {
                   3271:                             return $extdom;
                   3272:                         } 
                   3273:                         unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
                   3274:                             push(@possible_doms,$extdom);
                   3275:                         }
                   3276:                     }
                   3277:                 }
                   3278:             }
                   3279:             if (@possible_doms) {
                   3280:                 @possible_doms = sort(@possible_doms);
                   3281:                 return $possible_doms[0];
                   3282:             }
                   3283:         }
1.1       raeburn  3284:         $codedom = $env{'user.domain'};
                   3285:         if ($env{'request.role.domain'} ne '') {
                   3286:             $codedom = $env{'request.role.domain'};
                   3287:         }
                   3288:     }
                   3289:     return $codedom;
                   3290: }
                   3291: 
                   3292: sub display_navbuttons {
1.31      raeburn  3293:     my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1       raeburn  3294:     $r->print('<div class="LC_navbuttons">');
                   3295:     if ($prev) {
1.16      raeburn  3296:         $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31      raeburn  3297:                   'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16      raeburn  3298:                   ('&nbsp;'x3));
1.1       raeburn  3299:     } elsif ($prevtext) {
1.16      raeburn  3300:         $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
                   3301:                   'onclick="javascript:history.back()"/>'.('&nbsp;'x3));
                   3302:     }
                   3303:     if ($state eq 'details') {
                   3304:         $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31      raeburn  3305:                   'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16      raeburn  3306:                   ')" />');
1.1       raeburn  3307:     }
1.31      raeburn  3308:     my $gotnext;
1.15      raeburn  3309:     if ($state eq 'courseinfo') {
1.16      raeburn  3310:         $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   3311:                   'onclick="javascript:validateForm();" />');
1.31      raeburn  3312:         $gotnext = 1;
                   3313:     } elsif ($state eq 'enrollment') {
                   3314:         if (($env{'form.crstype'} eq 'official') && 
                   3315:             (&Apache::lonnet::auto_run('',$dom))) {
                   3316:             $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   3317:                       'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
                   3318:                 $gotnext = 1;
                   3319:         }
                   3320:     } elsif ($state eq 'personnel') {
                   3321:         if ($env{'form.persontotal'} > 0) { 
                   3322:             $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
                   3323:                       'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
                   3324:             $gotnext = 1;
                   3325:         }
                   3326:     }
                   3327:     unless ($gotnext) {
                   3328:         if ($next) {
                   3329:             $r->print('
                   3330:                       <input type="button" name="next" value="'.$nexttext.'" '.
                   3331:       'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
                   3332:         }
1.1       raeburn  3333:     }
                   3334:     $r->print('</div>');
                   3335: }
                   3336: 
                   3337: sub print_request_outcome {
1.66      raeburn  3338:     my ($dom,$codetitles,$code_order,$instcredits) = @_;
1.13      raeburn  3339:     my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.70      raeburn  3340:         %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,
                   3341:         $uniquecode);
1.24      raeburn  3342:     my $sectotal = $env{'form.sectotal'};
                   3343:     my $crosslisttotal = 0;
1.10      raeburn  3344:     $cnum = $env{'form.cnum'};
1.8       raeburn  3345:     unless ($cnum =~ /^$match_courseid$/) {
                   3346:         $output = &mt('Invalid LON-CAPA course number for the new course')."\n"; 
                   3347:         return $output;
                   3348:     }
1.73      raeburn  3349:     $crstype = $env{'form.crstype'};
                   3350:     my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9       raeburn  3351:     if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   3352:         if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
                   3353:             $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
                   3354:         }
1.73      raeburn  3355:         if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
                   3356:             $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
                   3357:         }
1.9       raeburn  3358:     }
1.10      raeburn  3359:     $now = time;
1.41      raeburn  3360:     my $ccrole = 'cc';
                   3361:     if ($crstype eq 'community') {
                   3362:         $ccrole = 'co';
                   3363:     }
1.17      raeburn  3364:     my @instsections;
1.8       raeburn  3365:     if ($crstype eq 'official') {
                   3366:         if (&Apache::lonnet::auto_run('',$dom)) {
1.13      raeburn  3367:             ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8       raeburn  3368:         }
1.10      raeburn  3369:         for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
                   3370:             if ($env{'form.sec_'.$i}) {
                   3371:                 if ($env{'form.secnum_'.$i} ne '') {
1.17      raeburn  3372:                     my $sec = $env{'form.secnum_'.$i};
                   3373:                     $sections{$i}{'inst'} = $sec;
                   3374:                     if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
                   3375:                         push(@instsections,$sec);
                   3376:                     }
1.13      raeburn  3377:                     $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.58      raeburn  3378:                     $sections{$i}{'loncapa'} =~ s/\W//g;
                   3379:                     if ($sections{$i}{'loncapa'} eq 'none') {
                   3380:                         $sections{$i}{'loncapa'} = '';
                   3381:                     }
1.10      raeburn  3382:                 }
                   3383:             }
                   3384:         }
                   3385:         for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
                   3386:             if ($env{'form.crosslist_'.$i}) {
                   3387:                 my $xlistinfo = '';
                   3388:                 if (ref($code_order) eq 'ARRAY') {
                   3389:                     if (@{$code_order} > 0) {
                   3390:                         foreach my $item (@{$code_order}) {
                   3391:                             $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
                   3392:                         }
                   3393:                     }
                   3394:                 }
1.22      raeburn  3395:                 $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24      raeburn  3396:                 if ($xlistinfo ne '') {
                   3397:                     $crosslisttotal ++;
                   3398:                 }
1.22      raeburn  3399:                 $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'}; 
1.13      raeburn  3400:                 $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10      raeburn  3401:             }
                   3402:         }
1.14      raeburn  3403:     } else {
                   3404:         $enrollstart = '';
                   3405:         $enrollend = '';
1.10      raeburn  3406:     }
1.62      raeburn  3407:     my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
1.10      raeburn  3408:     for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
                   3409:         my $uname = $env{'form.person_'.$i.'_uname'};
1.16      raeburn  3410:         my $udom = $env{'form.person_'.$i.'_dom'};
1.10      raeburn  3411:         if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
                   3412:             if (&Apache::lonnet::domain($udom) ne '') {
1.13      raeburn  3413:                 unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
                   3414:                     $personnel{$uname.':'.$udom} = {
                   3415:                              firstname    => $env{'form.person_'.$i.'_firstname'},
                   3416:                              lastname     => $env{'form.person_'.$i.'_lastname'},
                   3417:                              emailaddr    => $env{'form.person_'.$i.'_emailaddr'},
                   3418:                                                    };
1.62      raeburn  3419:                     if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
                   3420:                         my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
                   3421:                         if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
                   3422:                             my ($allowed,$msg,$authtype,$authparam) =
                   3423:                                 &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
                   3424:                                                      \%inst_results,\%curr_rules,\%got_rules);
                   3425:                             if ($allowed) {
                   3426:                                 my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
                   3427:                                 if ($usertype eq 'official') {
                   3428:                                     if ($authtype eq '') {
1.60      raeburn  3429:                                         $authtype = $domdefaults{'auth_def'};
                   3430:                                         $authparam = $domdefaults{'auth_arg_def'};
1.62      raeburn  3431:                                     } else {
                   3432:                                         if ($authtype eq 'loc') {
                   3433:                                             $authtype = 'localauth';
                   3434:                                         } elsif ($authtype eq 'int') {
                   3435:                                             $authtype = 'internal';
                   3436:                                         }
                   3437:                                         if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
                   3438:                                             $authtype = $domdefaults{'auth_def'};
                   3439:                                             $authparam = $domdefaults{'auth_arg_def'};
                   3440:                                         }
                   3441:                                     }
                   3442:                                 } elsif ($usertype eq 'unofficial') {
                   3443:                                     if ($authtype eq '') {
                   3444:                                         $authtype = 'internal';
                   3445:                                         $authparam = '';
1.60      raeburn  3446:                                     }
1.62      raeburn  3447:                                 } else {
                   3448:                                     $authtype = $domdefaults{'auth_def'};
                   3449:                                     $authparam = $domdefaults{'auth_arg_def'};
1.60      raeburn  3450:                                 }
1.62      raeburn  3451:                                 if (($authtype eq '') ||
                   3452:                                     (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
                   3453:                                     ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
                   3454:                                     $skipped{$uname.':'.$udom} = 1;
                   3455:                                     next;
                   3456:                                 } else {
                   3457:                                     $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
                   3458:                                     $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
1.60      raeburn  3459:                                 }
                   3460:                             } else {
1.62      raeburn  3461:                                 $skipped{$uname.':'.$udom} = 1;
1.60      raeburn  3462:                                 next;
                   3463:                             }
                   3464:                         } else {
1.62      raeburn  3465:                             $skipped{$uname.':'.$udom} = 1;
1.60      raeburn  3466:                             next;
                   3467:                         }
                   3468:                     }
1.13      raeburn  3469:                 }
                   3470:                 my $role = $env{'form.person_'.$i.'_role'};
                   3471:                 unless ($role eq '') {
1.16      raeburn  3472:                     if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13      raeburn  3473:                         my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
                   3474:                         unless (grep(/^\Q$role\E$/,@curr_roles)) {
                   3475:                             push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
                   3476:                         }
                   3477:                     } else {
                   3478:                         @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
                   3479:                     }
1.41      raeburn  3480:                     if ($role eq $ccrole) {
1.13      raeburn  3481:                         @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
                   3482:                     } else {
1.14      raeburn  3483:                         my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31      raeburn  3484:                         my @allsecs;
                   3485:                         foreach my $sec (@currsec) {
                   3486:                             next unless ($sec =~ /\w/);
                   3487:                             next if ($sec =~ /\W/);
                   3488:                             next if ($sec eq 'none');
                   3489:                             push(@allsecs,$sec);
                   3490:                         }
1.14      raeburn  3491:                         my $newsec = $env{'form.person_'.$i.'_newsec'};
                   3492:                         $newsec =~ s/^\s+//;
                   3493:                         $newsec =~s/\s+$//;
                   3494:                         my @newsecs = split(/[\s,;]+/,$newsec);
                   3495:                         foreach my $sec (@newsecs) {
                   3496:                             next if ($sec =~ /\W/);
1.31      raeburn  3497:                             next if ($sec eq 'none');
1.14      raeburn  3498:                             if ($sec ne '') {
1.31      raeburn  3499:                                 unless (grep(/^\Q$sec\E$/,@allsecs)) {
                   3500:                                     push(@allsecs,$sec);
1.13      raeburn  3501:                                 }
                   3502:                             }
                   3503:                         }
1.31      raeburn  3504:                         @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13      raeburn  3505:                     }
                   3506:                 }
1.10      raeburn  3507:             } else {
                   3508:                 push(@missingdom,$uname.':'.$udom);
                   3509:             }
                   3510:         } else {
                   3511:             push(@baduname,$uname.':'.$udom);
                   3512:         }
1.8       raeburn  3513:     }
1.62      raeburn  3514:     if (keys(%skipped)) {
                   3515:         foreach my $key (keys(%skipped)) {
                   3516:             delete($personnel{$key}); 
                   3517:         }
                   3518:     }
1.13      raeburn  3519:     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14      raeburn  3520:     my $autodrops = 0;
                   3521:     if ($env{'form.autodrops'}) {
                   3522:         $autodrops = $env{'form.autodrops'}; 
                   3523:     }
                   3524:     my $autoadds = 0;
                   3525:     if ($env{'form.autoadds'}) {
1.57      raeburn  3526:         $autoadds = $env{'form.autoadds'};
1.14      raeburn  3527:     }
                   3528:     my $instcode = '';
                   3529:     if (exists($env{'form.instcode'})) {
                   3530:         $instcode = $env{'form.instcode'};
                   3531:     }
1.66      raeburn  3532:     my $credits;
                   3533:     if ($instcredits) {
                   3534:         $credits = $instcredits;
                   3535:     } elsif (exists($env{'form.coursecredits'})) {
                   3536:         $credits = $env{'form.coursecredits'};
                   3537:     }
1.15      raeburn  3538:     my $clonecrs = '';
                   3539:     my $clonedom = '';
1.45      raeburn  3540:     if (($env{'form.cloning'}) &&
                   3541:         ($env{'form.clonecrs'} =~ /^($match_courseid)$/) && 
1.15      raeburn  3542:         ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16      raeburn  3543:         my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
                   3544:                                                     $env{'form.clonedom'});
1.15      raeburn  3545:         if ($clonehome ne 'no_host') {  
1.16      raeburn  3546:             my $canclone =  
                   3547:                 &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39      raeburn  3548:                         $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
                   3549:                         $crstype);
1.15      raeburn  3550:             if ($canclone) {
                   3551:                 $clonecrs = $env{'form.clonecrs'};
                   3552:                 $clonedom = $env{'form.clonedom'};
                   3553:             }
                   3554:         }
                   3555:     }
1.8       raeburn  3556:     my $details = {
1.10      raeburn  3557:                     owner          => $env{'user.name'},
                   3558:                     domain         => $env{'user.domain'}, 
                   3559:                     cdom           => $dom,
1.11      raeburn  3560:                     cnum           => $cnum,
1.13      raeburn  3561:                     coursehome     => $env{'form.chome'},
                   3562:                     cdescr         => $env{'form.cdescr'},
1.10      raeburn  3563:                     crstype        => $env{'form.crstype'},
1.14      raeburn  3564:                     instcode       => $instcode,
1.66      raeburn  3565:                     defaultcredits => $credits, 
1.70      raeburn  3566:                     uniquecode     => $uniquecode,
1.15      raeburn  3567:                     clonedom       => $clonedom,
                   3568:                     clonecrs       => $clonecrs,
1.10      raeburn  3569:                     datemode       => $env{'form.datemode'},
1.14      raeburn  3570:                     dateshift      => $env{'form.dateshift'},
                   3571:                     sectotal       => $sectotal,
1.10      raeburn  3572:                     sections       => \%sections,
1.14      raeburn  3573:                     crosslisttotal => $crosslisttotal,
1.13      raeburn  3574:                     crosslists     => \%crosslistings,
1.14      raeburn  3575:                     autoadds       => $autoadds,
                   3576:                     autodrops      => $autodrops,
1.13      raeburn  3577:                     enrollstart    => $enrollstart,
                   3578:                     enrollend      => $enrollend,
                   3579:                     accessstart    => $accessstart,
                   3580:                     accessend      => $accessend,
1.10      raeburn  3581:                     personnel      => \%personnel,
1.8       raeburn  3582:                   };
1.72      raeburn  3583:     my ($result,$output) = &process_request($dom,$cnum,$crstype,$now,$details,$instcode,
                   3584:                                             $req_notifylist,\@instsections,\%domconfig);
                   3585:     return ($result,$output);
                   3586: }
                   3587:     
                   3588: sub process_request {
                   3589:     my ($dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,$domconfig) = @_; 
                   3590:     my (@inststatuses,$storeresult,$creationresult,$output);
1.43      raeburn  3591:     my $val = 
1.64      raeburn  3592:         &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
                   3593:                                                       $env{'user.domain'},$env{'user.adv'},
1.72      raeburn  3594:                                                       $dom,$crstype,\@inststatuses,$domconfig);
1.8       raeburn  3595:     if ($val eq '') {
                   3596:         if ($crstype eq 'official') {
1.19      raeburn  3597:             $output = &mt('You are not permitted to request creation of official courses.');
1.8       raeburn  3598:         } elsif ($crstype eq 'unofficial') {
1.19      raeburn  3599:             $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8       raeburn  3600:         } elsif ($crstype eq 'community') {
                   3601:             $output = &mt('You are not permitted to request creation of communities');
1.69      raeburn  3602:         } elsif ($crstype eq 'textbook') {
                   3603:             $output = &mt('You are not permitted to request creation of textbook courses');
1.8       raeburn  3604:         } else {
                   3605:             $output = &mt('Unrecognized course type: [_1]',$crstype);
                   3606:         }
1.27      raeburn  3607:         $storeresult = 'notpermitted'; 
1.8       raeburn  3608:     } else {
1.14      raeburn  3609:         my ($disposition,$message,$reqstatus);
1.8       raeburn  3610:         my %reqhash = (
1.14      raeburn  3611:                         reqtime   => $now,
1.10      raeburn  3612:                         crstype   => $crstype,
                   3613:                         details   => $details,
1.8       raeburn  3614:                       );
                   3615:         my $requestkey = $dom.'_'.$cnum;
1.17      raeburn  3616:         my $validationerror;
1.10      raeburn  3617:         if ($val eq 'autolimit=') {
                   3618:             $disposition = 'process';
                   3619:         } elsif ($val =~ /^autolimit=(\d+)$/) {
                   3620:             my $limit = $1;
1.8       raeburn  3621:             $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10      raeburn  3622:                                             $dom,$crstype,$limit,\$message);
1.8       raeburn  3623:         } elsif ($val eq 'validate') {
1.21      raeburn  3624:             my ($inststatuslist,$validationchk,$validation);
1.17      raeburn  3625:             if (@inststatuses > 0) {
                   3626:                 $inststatuslist = join(',',@inststatuses);
                   3627:             }
                   3628:             my $instseclist;
1.72      raeburn  3629:             if (ref($instsections) eq 'ARRAY') {
                   3630:                 if (@{$instsections} > 0) {
                   3631:                     $instseclist = join(',',@{$instsections});
                   3632:                 }
1.17      raeburn  3633:             }
1.21      raeburn  3634:             $validationchk = 
                   3635:                 &Apache::lonnet::auto_courserequest_validation($dom,
                   3636:                     $env{'user.name'}.':'.$env{'user.domain'},$crstype,
                   3637:                     $inststatuslist,$instcode,$instseclist);
                   3638:             if ($validationchk =~ /:/) {
                   3639:                 ($validation,$message) = split(':',$validationchk);
                   3640:             } else {
                   3641:                 $validation = $validationchk;
                   3642:             }
                   3643:             if ($validation =~ /^error(.*)$/) {
1.17      raeburn  3644:                 $disposition = 'approval';
                   3645:                 $validationerror = $1;
1.23      raeburn  3646:             } else {
                   3647:                 $disposition = $validation;
1.17      raeburn  3648:             }
1.8       raeburn  3649:         } else {
                   3650:             $disposition = 'approval';
                   3651:         }
1.14      raeburn  3652:         $reqhash{'disposition'} = $disposition;
                   3653:         $reqstatus = $disposition;
1.73      raeburn  3654:         my ($modified,$queued,$coursedesc,%customitems);
                   3655:         unless ($disposition eq 'rejected') {
                   3656:             if (ref($details) eq 'HASH') {
                   3657:                 $coursedesc = $details->{'cdescr'};
                   3658:             }
                   3659:             my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                   3660:                                                          $env{'user.domain'});
                   3661:             my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
                   3662:                                                                 $env{'user.domain'},$fullname,$coursedesc);
                   3663:             if (ref($inprocess) eq 'HASH') {
                   3664:                 if (ref($inprocess->{'formitems'}) eq 'HASH') {
                   3665:                     foreach my $key (keys(%{$inprocess->{'formitems'}})) {
                   3666:                         if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
                   3667:                             if (exists($env{'form.'.$key})) {
                   3668:                                 @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
                   3669:                             }
                   3670:                         } else {
                   3671:                             if (exists($env{'form.'.$key})) {
                   3672:                                 $customitems{$key} = $env{'form.'.$key};
                   3673:                                 $reqhash{'custom'}{$key} = $customitems{$key};
                   3674:                             }
                   3675:                         }
                   3676:                     }
                   3677:                 }
                   3678:             }
                   3679:         }
1.8       raeburn  3680:         if ($disposition eq 'rejected') {
1.40      raeburn  3681:             if ($crstype eq 'community') {
                   3682:                 $output = &mt('Your community request was rejected.');
                   3683:             } else {
                   3684:                 $output = &mt('Your course request was rejected.');
                   3685:             }
1.8       raeburn  3686:             if ($message) {
                   3687:                 $output .= '<div class="LC_warning">'.$message.'</div>';
                   3688:             }
1.27      raeburn  3689:             $storeresult = 'rejected';
1.8       raeburn  3690:         } elsif ($disposition eq 'process') {
1.14      raeburn  3691:             my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.70      raeburn  3692:             my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
1.8       raeburn  3693:             my $type = 'Course';
                   3694:             if ($crstype eq 'community') {
                   3695:                 $type = 'Community';
                   3696:             }
1.41      raeburn  3697:             my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8       raeburn  3698:             foreach my $role (@roles) {
                   3699:                 $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
                   3700:             }
1.73      raeburn  3701:             my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
                   3702:                                           'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
                   3703:                                           \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
                   3704:                                           \$code,\%customitems);
1.14      raeburn  3705:             if ($result eq 'created') {
1.8       raeburn  3706:                 $disposition = 'created';
1.14      raeburn  3707:                 $reqstatus = 'created';
1.28      raeburn  3708:                 my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
                   3709:                                                            \%longroles);
1.40      raeburn  3710:                 if ($crstype eq 'community') {
                   3711:                     $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
                   3712:                 } else {
                   3713:                     $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
                   3714:                 }
1.73      raeburn  3715:                 if (($code) || ((ref($postprocess) eq 'HASH') && 
                   3716:                                 (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
                   3717:                     $output .= &notification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
1.74      raeburn  3718:                                                          $dom,$cnum,$now,$code,$postprocess);
1.73      raeburn  3719:                 }
1.70      raeburn  3720:                 if ($code) {
1.73      raeburn  3721:                     $reqhash{'code'} = $code;
1.70      raeburn  3722:                 }
1.40      raeburn  3723:                 $output .= '<br />'.$role_result.'</p>';
1.27      raeburn  3724:                 $creationresult = 'created';
1.8       raeburn  3725:             } else {
1.40      raeburn  3726:                 $output = '<span class="LC_error">';
                   3727:                 if ($crstype eq 'community') {
                   3728:                     $output .= &mt('An error occurred when processing your community request.');
                   3729:                 } else {
                   3730:                     $output .= &mt('An error occurred when processing your course request.');
                   3731:                 }
                   3732:                 $output .= '<br />'.
                   3733:                            &mt('You may want to review the request details and submit the request again.').
1.14      raeburn  3734:                           '</span>';
1.27      raeburn  3735:                 $creationresult = 'error';
1.8       raeburn  3736:             }
                   3737:         } else {
                   3738:             my $requestid = $cnum.'_'.$disposition;
1.73      raeburn  3739:             my $request = {
1.8       raeburn  3740:                             $requestid => {
                   3741:                                             timestamp   => $now,
                   3742:                                             crstype     => $crstype,
                   3743:                                             ownername   => $env{'user.name'},
                   3744:                                             ownerdom    => $env{'user.domain'},
1.13      raeburn  3745:                                             description => $env{'form.cdescr'}, 
1.8       raeburn  3746:                                           },
                   3747:                           };
1.49      raeburn  3748:             if ($crstype eq 'official') {
                   3749:                 $request->{$requestid}->{'instcode'} = $instcode;
                   3750:             }
1.16      raeburn  3751:             my $statuskey = 'status:'.$dom.':'.$cnum;
                   3752:             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                   3753:                                                    $env{'user.domain'},$env{'user.name'});
1.17      raeburn  3754:             if ($userreqhash{$statuskey} ne '') {
1.16      raeburn  3755:                 $modified = 1;
1.25      raeburn  3756:                 my $uname = &Apache::lonnet::get_domainconfiguser($dom);
                   3757:                 my %queuehash = &Apache::lonnet::get('courserequestqueue',
                   3758:                                                      [$cnum.'_approval',
                   3759:                                                       $cnum.'_pending'],$dom,$uname);
1.17      raeburn  3760:                 if (($queuehash{$cnum.'_approval'} ne '') || 
                   3761:                     ($queuehash{$cnum.'_pending'} ne '')) {
1.16      raeburn  3762:                     $queued = 1;
                   3763:                 }
                   3764:             }
                   3765:             unless ($queued) {
                   3766:                 my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
                   3767:                                                             $dom);
                   3768:                 if ($putresult eq 'ok') {
1.40      raeburn  3769:                     if ($crstype eq 'community') {
                   3770:                         $output .= &mt('Your community request has been recorded.');
                   3771:                     } else {
                   3772:                         $output .= &mt('Your course request has been recorded.') 
                   3773:                     }
                   3774:                     $output .= '<br />'.
1.16      raeburn  3775:                               &notification_information($disposition,$req_notifylist,
1.74      raeburn  3776:                                                         $dom,$cnum,$now);
1.8       raeburn  3777:                 } else {
1.16      raeburn  3778:                     $reqstatus = 'domainerror';
                   3779:                     $reqhash{'disposition'} = $disposition;
                   3780:                     my $warning = &mt('An error occurred saving your request in the pending requests queue.');
                   3781:                     $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8       raeburn  3782:                 }
                   3783:             }
                   3784:         }
1.44      raeburn  3785:         ($storeresult,my $updateresult) = 
                   3786:             &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
1.63      raeburn  3787:                 $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
1.16      raeburn  3788:         if ($modified && $queued && $storeresult eq 'ok') {
1.40      raeburn  3789:             if ($crstype eq 'community') {
                   3790:                 $output .= '<p>'.&mt('Your community request has been updated').'</p>';
                   3791:             } else {
                   3792:                 $output .= '<p>'.&mt('Your course request has been updated').'</p>';
                   3793:             }
1.74      raeburn  3794:             $output .= &notification_information($disposition,$req_notifylist,$dom,$cnum,$now);
1.73      raeburn  3795:             if ($disposition eq 'approval') {
                   3796:                 my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                   3797:                                                              $env{'user.domain'});
                   3798:                 my $postprocess = 
                   3799:                     &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'queued',$env{'user.name'},
                   3800:                                                         $env{'user.domain'},$fullname,$env{'form.cdescr'});
                   3801:                 if ((ref($postprocess) eq 'HASH') && 
                   3802:                     ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) { 
1.77    ! raeburn  3803:                     &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
1.73      raeburn  3804:                 }
                   3805:             }
1.16      raeburn  3806:         }
1.17      raeburn  3807:         if ($validationerror ne '') {
1.44      raeburn  3808:             $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
                   3809:         }
                   3810:         if ($updateresult) {
                   3811:             $output .= $updateresult;
1.17      raeburn  3812:         }
1.16      raeburn  3813:     }
1.27      raeburn  3814:     if ($creationresult ne '') {
                   3815:         return ($creationresult,$output);
                   3816:     } else {
                   3817:         return ($storeresult,$output);
                   3818:     }
1.16      raeburn  3819: }
                   3820: 
1.28      raeburn  3821: sub update_requestors_roles {
                   3822:     my ($dom,$cnum,$crstype,$details,$longroles) = @_;
                   3823:     my $now = time;
                   3824:     my ($active,$future,$numactive,$numfuture,$output);
                   3825:     my $owner = $env{'user.name'}.':'.$env{'user.domain'};
                   3826:     if (ref($details) eq 'HASH') {
                   3827:         if (ref($details->{'personnel'}) eq 'HASH') {
1.41      raeburn  3828:             my $ccrole = 'cc';
                   3829:             if ($crstype eq 'community') {
                   3830:                 $ccrole = 'co';
                   3831:             }
1.35      raeburn  3832:             unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
                   3833:                 $details->{'personnel'}{$owner} = {
1.41      raeburn  3834:                                                     'roles' => [$ccrole],
                   3835:                                                     $ccrole => { 'usec' => [] },
1.35      raeburn  3836:                                                   };
                   3837:             }
                   3838:             my @roles;
                   3839:             if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
                   3840:                 @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41      raeburn  3841:                 unless (grep(/^\Q$ccrole\E$/,@roles)) {
                   3842:                     push(@roles,$ccrole);
1.35      raeburn  3843:                 }
                   3844:             } else {
1.41      raeburn  3845:                 @roles = ($ccrole);
1.35      raeburn  3846:             }
                   3847:             foreach my $role (@roles) {
1.42      raeburn  3848:                 my $refresh=$env{'user.refresh.time'};
                   3849:                 if ($refresh eq '') {
                   3850:                     $refresh = $env{'user.login.time'};
                   3851:                 }
                   3852:                 if ($refresh eq '') {
                   3853:                     $refresh = $now;
                   3854:                 }
                   3855:                 my $start = $refresh-1;
1.35      raeburn  3856:                 my $end = '0';
                   3857:                 if ($role eq 'st') {
                   3858:                     if ($details->{'accessstart'} ne '') {
                   3859:                         $start = $details->{'accessstart'};
                   3860:                     }
                   3861:                     if ($details->{'accessend'} ne '') {
                   3862:                         $end = $details->{'accessend'};
                   3863:                     }
                   3864:                 }
                   3865:                 my @usecs;
1.41      raeburn  3866:                 if ($role ne $ccrole) {
1.35      raeburn  3867:                     if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
                   3868:                         @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
                   3869:                     }
                   3870:                 } 
                   3871:                 if ($role eq 'st') {
                   3872:                     if (@usecs > 1) {
                   3873:                         my $firstsec = $usecs[0];
                   3874:                         @usecs = ($firstsec);
                   3875:                     }
                   3876:                 }
                   3877:                 if (@usecs == 0) {
                   3878:                     push(@usecs,'');
                   3879:                 }
                   3880:                 foreach my $usec (@usecs) {
                   3881:                     my (%userroles,%newrole,%newgroups,$spec,$area);
                   3882:                     my $area = '/'.$dom.'/'.$cnum;
                   3883:                     my $spec = $role.'.'.$area;
                   3884:                     if ($usec ne '') {
                   3885:                        $spec .= '/'.$usec;
                   3886:                        $area .= '/'.$usec;
                   3887:                     }
                   3888:                     if ($role =~ /^cr\//) {
                   3889:                         &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
                   3890:                                                           $cnum,$spec,$area);
                   3891:                     } else {
                   3892:                         &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
                   3893:                                                             $spec,$cnum,$area);
1.28      raeburn  3894:                     }
1.35      raeburn  3895:                     &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
                   3896:                                                    \%newgroups);
                   3897:                     $userroles{'user.role.'.$spec} = $start.'.'.$end;
                   3898:                     &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
                   3899:                     if (($end == 0) || ($end > $now)) {
                   3900:                         my $showrole = $role;
1.28      raeburn  3901:                         if ($role =~ /^cr\//) {
1.35      raeburn  3902:                             $showrole = &Apache::lonnet::plaintext($role,$crstype);
                   3903:                         } elsif (ref($longroles) eq 'HASH') {
                   3904:                             if ($longroles->{$role} ne '') {
                   3905:                                 $showrole = $longroles->{$role};
                   3906:                             }
1.28      raeburn  3907:                         }
1.35      raeburn  3908:                         if ($start <= $now) {
                   3909:                             $active .= '<li><a href="/adm/roles?selectrole=1&'.
                   3910:                                        $spec.'=1">'.$showrole;
                   3911:                             if ($usec ne '') {
                   3912:                                 $active .= ' - '.&mt('section:').' '.$usec; 
1.28      raeburn  3913:                             }
1.35      raeburn  3914:                             $active .= '</a></li>';
                   3915:                             $numactive ++;
                   3916:                         } else { 
                   3917:                             $future .= '<li>'.$showrole;
                   3918:                             if ($usec ne '') {
                   3919:                                 $future .= ' - '.&mt('section:').' '.$usec;
1.28      raeburn  3920:                             }
1.35      raeburn  3921:                             $future .= '</li>';
                   3922:                             $numfuture ++;
1.28      raeburn  3923:                         }
                   3924:                     }
                   3925:                 }
                   3926:             }
                   3927:         }
                   3928:     }
                   3929:     if ($active) {
                   3930:         if ($numactive == 1) {
1.41      raeburn  3931:             if ($crstype eq 'Community') {
                   3932:                 $output = &mt('Use the following link to enter the community:');
                   3933:             } else {
                   3934:                 $output = &mt('Use the following link to enter the course:'); 
                   3935:             }
1.28      raeburn  3936:         } else {
1.41      raeburn  3937:             if ($crstype eq 'Community') {
                   3938:                 $output = &mt('Use the following links to your new roles to enter the community:');
                   3939:             } else {
                   3940:                 $output = &mt('Use the following links to your new roles to enter the course:');
                   3941:             }
1.28      raeburn  3942:         }
                   3943:         $output .= ' <ul>'.$active.'</ul><br />';
                   3944:     }
                   3945:     if ($future) {
1.41      raeburn  3946:         if ($crstype eq 'Community') {
                   3947:             $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'}))
                   3948:         } else {
                   3949:             $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'}));
                   3950:         }
                   3951:         $output .= ' <ul>'.$future.'</ul>';
1.28      raeburn  3952:     }
                   3953:     return $output;
                   3954: }
                   3955: 
1.16      raeburn  3956: sub notification_information {
1.74      raeburn  3957:     my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
1.16      raeburn  3958:     my %emails = &Apache::loncommon::getemails();
                   3959:     my $address;
                   3960:     if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
                   3961:         $address = $emails{'permanentemail'};
                   3962:         if ($address eq '') {
                   3963:             $address = $emails{'notification'};
                   3964:         }
                   3965:     }
                   3966:     my $output;
                   3967:     if ($disposition eq 'approval') {
                   3968:         $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
                   3969:                    &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
                   3970:         if ($address ne '') {
                   3971:             $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
                   3972:         }
                   3973:         if ($req_notifylist) {
                   3974:             my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1.73      raeburn  3975:                                                          $env{'user.domain'});
1.16      raeburn  3976:             my $sender = $env{'user.name'}.':'.$env{'user.domain'};
1.74      raeburn  3977:             &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
                   3978:                                                                       'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
1.16      raeburn  3979:         }
1.73      raeburn  3980:         if (ref($postprocess) eq 'HASH') {
                   3981:             if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
                   3982:                 if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
                   3983:                     my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
                   3984:                     my $sender = $recipient;
                   3985:                     my $addmsg = [];
                   3986:                     foreach my $item (@{$postprocess->{'queuedmsg'}}) {
                   3987:                         if (ref($item) eq 'HASH') {
                   3988:                             if ($item->{'mt'} ne '') {
                   3989:                                 push(@{$addmsg},$item);
                   3990:                             }
                   3991:                         }
                   3992:                     }
                   3993:                     if (scalar(@{$addmsg}) > 0) {
1.74      raeburn  3994:                         &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
1.73      raeburn  3995:                                                                                   $env{'form.cdescr'},$now,
1.77    ! raeburn  3996:                                                                                   'queuedcrsreq',$sender);
1.73      raeburn  3997:                     }
                   3998:                 }
                   3999:             }
                   4000:             if ($postprocess->{'queuedweb'}) {
                   4001:                 $output .= $postprocess->{'queuedweb'};
                   4002:             }
                   4003:         }
1.17      raeburn  4004:     } elsif ($disposition eq 'pending') {
1.16      raeburn  4005:         $output .= '<div class="LC_info">'.
                   4006: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
                   4007: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
                   4008: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
                   4009:                    '</div>';
1.73      raeburn  4010:     } elsif ($disposition eq 'created') {
                   4011:         if (($code) || ((ref($postprocess) eq 'HASH') && 
                   4012:             ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
                   4013:             my $addmsg = [];
                   4014:             my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
                   4015:             my $sender = $recipient;
                   4016:             if ($code) {
                   4017:                 push(@{$addmsg},{
1.74      raeburn  4018:                                   mt   => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
                   4019:                                   args => [$env{'form.cdescr'},$code],
1.73      raeburn  4020:                                 });
                   4021:                 $output .= '<p>'.
                   4022:                            &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
                   4023:                            '<br />'.
                   4024:                            &mt('A message has been sent to your LON-CAPA account with this information.');
                   4025:                 if ($address ne '') {
                   4026:                     $output.= '<br />'.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
                   4027:                 }
                   4028:                 $output .= '</p>';
                   4029:             }
                   4030:             if (ref($postprocess) eq 'HASH') {
                   4031:                 if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
                   4032:                     foreach my $item (@{$postprocess->{'createdmsg'}}) {
                   4033:                         if (ref($item) eq 'HASH') {
                   4034:                             if ($item->{'mt'} ne '') {  
                   4035:                                 push(@{$addmsg},$item);
                   4036:                             }
                   4037:                         }
                   4038:                     }
                   4039:                 }
                   4040:                 if ($postprocess->{'createdweb'}) {
                   4041:                     $output .= $postprocess->{'createdweb'}
                   4042:                 }
                   4043:             }
                   4044:             if (scalar(@{$addmsg}) > 0) {
1.77    ! raeburn  4045:                 my $type = 'createdcrsreq';
1.73      raeburn  4046:                 if ($code) {
                   4047:                     $type = 'uniquecode';
                   4048:                 }
1.74      raeburn  4049:                 &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
1.73      raeburn  4050:                                                                           $now,$type,$sender);
                   4051:             }
1.70      raeburn  4052:         }
1.17      raeburn  4053:     } else {
                   4054:         $output .= '<div class="LC_warning">'.
1.44      raeburn  4055:                    &mt('Your request status is: [_1].',$disposition).
                   4056:                    '</div>';
1.8       raeburn  4057:     }
                   4058:     return $output;
                   4059: }
                   4060: 
                   4061: sub check_autolimit {
1.10      raeburn  4062:     my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
                   4063:     my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41      raeburn  4064:                        'userroles',['active','future'],['cc','co'],[$dom]);
1.37      raeburn  4065:     my ($types,$typename) = &Apache::loncommon::course_types();
1.10      raeburn  4066:     my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41      raeburn  4067:     my $count = 0;
1.10      raeburn  4068:     foreach my $key (keys(%requests)) {
                   4069:         my ($cdom,$cnum) = split('_',$key);
1.41      raeburn  4070:         if (ref($requests{$key}) eq 'HASH') {
                   4071:             next if ($requests{$key}{'crstype'} ne $crstype);
                   4072:             if (($crstype eq 'community') && 
                   4073:                 (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
                   4074:                 $count ++;
1.69      raeburn  4075:             } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) &&
1.41      raeburn  4076:                      (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
                   4077:                 $count ++;
1.10      raeburn  4078:             }
                   4079:         }
                   4080:     }
1.41      raeburn  4081:     if ($count < $limit) {
1.10      raeburn  4082:         return 'process';
                   4083:     } else {
                   4084:         if (ref($typename) eq 'HASH') {
1.41      raeburn  4085:             if ($crstype eq 'community') {
                   4086:                 $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
                   4087:                             '<br />'.&mt("Your limit is [_1].",$limit);
                   4088:             } else {
                   4089:                 $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
                   4090:                             '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
                   4091:             }
1.10      raeburn  4092:         }
                   4093:         return 'rejected';
                   4094:     }
1.1       raeburn  4095:     return;
                   4096: }
                   4097: 
1.2       raeburn  4098: sub retrieve_settings {
1.26      raeburn  4099:     my ($dom,$cnum,$udom,$uname) = @_;
                   4100:     if ($udom eq '' || $uname eq '') {
                   4101:         $udom = $env{'user.domain'};
                   4102:         $uname = $env{'user.name'};
                   4103:     }
                   4104:     my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16      raeburn  4105:     if ($result eq 'ok') {
1.26      raeburn  4106:         if (($udom eq $reqinfo{'domain'}) &&  ($uname eq $reqinfo{'owner'})) {
1.16      raeburn  4107:             $env{'form.chome'} = $reqinfo{'coursehome'};
                   4108:             $env{'form.cdescr'} = $reqinfo{'cdescr'};
                   4109:             $env{'form.crstype'} = $reqinfo{'crstype'}; 
                   4110:             &generate_date_items($reqinfo{'accessstart'},'accessstart');
                   4111:             &generate_date_items($reqinfo{'accessend'},'accessend');
                   4112:             if ($reqinfo{'accessend'} == 0) {
                   4113:                 $env{'form.no_end_date'} = 1;
                   4114:             }
                   4115:             if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
                   4116:                 &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
                   4117:                 &generate_date_items($reqinfo{'enrollend'},'enrollend');
                   4118:             }
                   4119:             $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
                   4120:             $env{'form.clonedom'} = $reqinfo{'clonedom'};
1.55      raeburn  4121:             if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
                   4122:                 $env{'form.cloning'} = 1;
                   4123:             }
1.16      raeburn  4124:             $env{'form.datemode'} = $reqinfo{'datemode'};
                   4125:             $env{'form.dateshift'} = $reqinfo{'dateshift'};
1.59      raeburn  4126:             if ($reqinfo{'crstype'} eq 'official') {
                   4127:                 $env{'form.autoadds'} = $reqinfo{'autoadds'};
                   4128:                 $env{'form.autodrops'} = $reqinfo{'autodrops'};
                   4129:                 if ($reqinfo{'instcode'} ne '') { 
                   4130:                     $env{'form.sectotal'} = $reqinfo{'sectotal'};
                   4131:                     $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
                   4132:                     $env{'form.instcode'} = $reqinfo{'instcode'};
                   4133:                     my $crscode = { 
                   4134:                                     $cnum => $reqinfo{'instcode'},
                   4135:                                   };
                   4136:                     &extract_instcode($dom,'instcode',$crscode,$cnum);
1.66      raeburn  4137:                     (undef,undef,my $instcredits) =
                   4138:                         &Apache::lonnet::auto_validate_instcode(undef,$dom,
                   4139:                                                                 $reqinfo{'instcode'});
                   4140:                     if ($instcredits ne $reqinfo{'defaultcredits'}) {
                   4141:                         $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
                   4142:                     }
1.59      raeburn  4143:                 }
1.69      raeburn  4144:             } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
1.66      raeburn  4145:                 $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
1.16      raeburn  4146:             }
                   4147:             my @currsec;
                   4148:             if (ref($reqinfo{'sections'}) eq 'HASH') {
                   4149:                 foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
                   4150:                     if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24      raeburn  4151:                         my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16      raeburn  4152:                         $env{'form.secnum_'.$i} = $sec;
1.24      raeburn  4153:                         $env{'form.sec_'.$i} = '1';
1.16      raeburn  4154:                         if (!grep(/^\Q$sec\E$/,@currsec)) {
                   4155:                             push(@currsec,$sec);
                   4156:                         }
                   4157:                         $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
                   4158:                     }
                   4159:                 }
                   4160:             }
1.24      raeburn  4161:             if (ref($reqinfo{'crosslists'}) eq 'HASH') {
                   4162:                 foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
                   4163:                     if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
                   4164:                         $env{'form.crosslist_'.$i} = '1';
                   4165:                         $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
                   4166:                         $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
                   4167:                         if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
                   4168:                             my $key = $cnum.$i; 
                   4169:                             my $crscode = {
                   4170:                                               $key => $reqinfo{'crosslists'}{$i}{'instcode'},
                   4171:                                           };
                   4172:                             &extract_instcode($dom,'crosslist',$crscode,$key,$i);
                   4173:                         }
1.16      raeburn  4174:                     }
                   4175:                 }
                   4176:             }
                   4177:             if (ref($reqinfo{'personnel'}) eq 'HASH') {
                   4178:                 my $i = 0;
                   4179:                 foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
                   4180:                     my ($uname,$udom) = split(':',$user);
                   4181:                     if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
                   4182:                         if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
                   4183:                             foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
                   4184:                                 $env{'form.person_'.$i.'_role'} = $role;
                   4185:                                 $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
                   4186:                                 $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
                   4187:                                 $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
                   4188:                                 $env{'form.person_'.$i.'_uname'} = $uname;
                   4189:                                 $env{'form.person_'.$i.'_dom'} = $udom;
                   4190:                                 if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
                   4191:                                     if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
                   4192:                                         my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
                   4193:                                         my @newsecs;
                   4194:                                         if (@usecs > 0) {
                   4195:                                             foreach my $sec (@usecs) {
                   4196:                                                 if (grep(/^\Q$sec\E/,@currsec)) {
                   4197:                                                     $env{'form.person_'.$i.'_sec'} = $sec;
                   4198:                                                 } else {
1.20      raeburn  4199:                                                     push(@newsecs,$sec);
1.16      raeburn  4200:                                                 }
                   4201:                                             }
                   4202:                                         }
                   4203:                                         if (@newsecs > 0) {
                   4204:                                             $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs); 
                   4205:                                         }
                   4206:                                     }
                   4207:                                 }
                   4208:                                 $i ++;
                   4209:                             }
                   4210:                         }
                   4211:                     }
                   4212:                 }
                   4213:                 $env{'form.persontotal'} = $i;
                   4214:             }
                   4215:         }
                   4216:     }
                   4217:     return $result;
                   4218: }
                   4219: 
                   4220: sub get_request_settings {
1.26      raeburn  4221:     my ($dom,$cnum,$udom,$uname) = @_;
1.16      raeburn  4222:     my $requestkey = $dom.'_'.$cnum;
                   4223:     my ($result,%reqinfo);
                   4224:     if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26      raeburn  4225:         my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16      raeburn  4226:         my $disposition = $history{'disposition'};
                   4227:         if (($disposition eq 'approval') || ($disposition eq 'pending')) { 
                   4228:             if (ref($history{'details'}) eq 'HASH') {
                   4229:                 %reqinfo = %{$history{'details'}};
                   4230:                 $result = 'ok';
                   4231:             } else {
                   4232:                 $result = 'nothash';
                   4233:             }
                   4234:         } else {
                   4235:             $result = 'notqueued';
                   4236:         }
                   4237:     } else {
                   4238:         $result = 'invalid';
                   4239:     }
                   4240:     return ($result,%reqinfo);
                   4241: }
1.2       raeburn  4242: 
1.16      raeburn  4243: sub extract_instcode {
1.24      raeburn  4244:     my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16      raeburn  4245:     my (%codes,@codetitles,%cat_titles,%cat_order);
1.24      raeburn  4246:     if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
                   4247:                                               \@codetitles,\%cat_titles,
                   4248:                                               \%cat_order) eq 'ok') {
                   4249:         if (ref($codes{$crskey}) eq 'HASH') {
1.16      raeburn  4250:             if (@codetitles > 0) {
                   4251:                 my $sel = $element;
                   4252:                 if ($element eq 'crosslist') {
                   4253:                     $sel .= '_'.$counter;
                   4254:                 }
                   4255:                 foreach my $title (@codetitles) {
1.24      raeburn  4256:                     $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16      raeburn  4257:                 }
                   4258:             }
                   4259:         }
                   4260:     }
                   4261:     return;
1.2       raeburn  4262: }
                   4263: 
1.16      raeburn  4264: sub generate_date_items {
                   4265:     my ($currentval,$item) = @_;
                   4266:     if ($currentval =~ /\d+/) {
                   4267:         my ($tzname,$sec,$min,$hour,$mday,$month,$year) = 
                   4268:             &Apache::lonhtmlcommon::get_timedates($currentval);
                   4269:         $env{'form.'.$item.'_day'} = $mday;
                   4270:         $env{'form.'.$item.'_month'} = $month+1;
                   4271:         $env{'form.'.$item.'_year'} = $year;
                   4272:     }
                   4273:     return;
1.2       raeburn  4274: }
                   4275: 
1.72      raeburn  4276: sub print_textbook_form {
1.73      raeburn  4277:     my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
1.72      raeburn  4278:     my ($bookshash,%ordered);
                   4279:     my $crstype = 'textbook';
                   4280: #
                   4281: #  Retrieve list of textbook courses cloneable by user
                   4282: #
                   4283:     my $numbook;
                   4284:     if (ref($settings) eq 'HASH') {
                   4285:         $bookshash = $settings->{'textbooks'};
                   4286:         if (ref($bookshash) eq 'HASH') {
                   4287:             foreach my $item (keys(%{$bookshash})) {
                   4288:                 my ($clonedom,$clonecrs) = split(/_/,$item);
                   4289:                 if (ref($bookshash->{$item}) eq 'HASH') {
                   4290:                     my ($clonedom,$clonecrs) = split(/_/,$item);
                   4291:                     if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
                   4292:                                         $env{'user.domain'},$clonecrs,$clonedom,$crstype)) {
                   4293: 
                   4294:                         my $num = $bookshash->{$item}{'order'};
                   4295:                         $ordered{$num} = $item;
                   4296:                         $numbook ++;
                   4297:                     }
                   4298:                 }
                   4299:             }
                   4300:         }
                   4301:     }
                   4302: 
                   4303: #
                   4304: # Check if domain has multiple library servers
                   4305: #
                   4306:     my ($home_server_pick,$numlib) =
                   4307:         &Apache::loncommon::home_server_form_item($dom,'chome',
                   4308:                                                   'default','hide');
                   4309:     if ($numlib > 1) {
                   4310:         $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.'<br />';
                   4311:     }
                   4312: 
                   4313: #
                   4314: # Retrieve information about courses owned by user, or in which user has an active or future 
                   4315: # Course Coordinator role 
                   4316: #
                   4317:     my $numcurrent;
                   4318:     my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
                   4319:                                               undef,undef,undef,'Course');
                   4320:     my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   4321:                                                 ['active','future'],['cc']);
                   4322:     foreach my $role (keys(%ccroles)) {
                   4323:         my ($cnum,$cdom,$rest) = split(/:/,$role,3);
                   4324:         unless (exists($cloneable{$cdom.'_'.$cnum})) {
                   4325:             my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
                   4326:             $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
                   4327:         }
                   4328:     }
                   4329: 
                   4330:     my $numcurrent = scalar(keys(%cloneable));
                   4331: 
                   4332:     my $jscript = &textbook_request_javascript($numbook,$numcurrent);
                   4333:     my %loaditems;
                   4334:     $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
                   4335:     $r->print(&header('Course Request',$jscript,\%loaditems));
                   4336: 
1.73      raeburn  4337:     if (ref($can_request) eq 'HASH') {
                   4338:         unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
                   4339:             &Apache::lonhtmlcommon::add_breadcrumb(
                   4340:                 { href => '/adm/requestcourse',
                   4341:                   text => 'Pick action',
                   4342:                 });
                   4343:         }
                   4344:     }
1.72      raeburn  4345:     &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
                   4346:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
                   4347: 
1.73      raeburn  4348:     &startContentScreen($r,'textbookrequests');
1.72      raeburn  4349: #
                   4350: # Show domain selector form, if required.
                   4351: #
                   4352:     if (@{$incdoms} > 1) {
                   4353:         my $onchange = 'this.form.submit()';
                   4354:         $r->print('<form name="domforcourse" method="post" action="/adm/requestcourse">'.
                   4355:                   '<div><fieldset><legend>'.&mt('Domain').'</legend>'.
                   4356:                   &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms).
                   4357:                   '</fieldset></form>');
                   4358:     }
                   4359: 
                   4360: #
                   4361: # Course request form
                   4362: #
                   4363: 
                   4364: #
                   4365: # Course Title
                   4366: #
                   4367:     $r->print('<form name="requestcourse" method="post" action="/adm/requestcourse" onsubmit="return validTextbookReq();">'.
                   4368:               '<div>'.
                   4369:               '<fieldset>'.
                   4370:               '<legend>'.&mt('Course Information').'</legend>'.
                   4371:               '<span class="LC_nobreak">'.&mt('Title').':&nbsp'.
                   4372:               '<input type="text" size="60" name="cdescr" value="" /></span><br />'.
                   4373:               $home_server_pick.'<br /></fieldset>'.
                   4374:               '</div>');
                   4375: 
                   4376: #
                   4377: # Content source selection, if more than one available
                   4378: #
                   4379:     if (keys(%cloneable) || keys(%ordered)) {
                   4380:         $r->print('<div>'. 
                   4381:                   '<fieldset><legend>'.&mt('Course Content').'</legend>');
                   4382:         if (keys(%ordered)) {
                   4383:             $r->print('<span class="LC_nobreak"><label>'.
                   4384:                       '<input type="radio" name="cloning" value="textbook" onclick="javascript:cloneChoice();" />'.
                   4385:                       &mt('Load textbook content').'</span>'.('&nbsp;'x2).' ');
                   4386:         }
                   4387:         if (keys(%cloneable)) {
                   4388:             $r->print('<span class="LC_nobreak"><label>'.
                   4389:                       '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'.
                   4390:                       &mt('Copy one of your courses').'</label></span>'.('&nbsp;'x2).' ');
                   4391:         }
                   4392:         $r->print('<span class="LC_nobreak"><label>'.
                   4393:                   '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'.
                   4394:                   &mt('Empty course shell').'</label></span>');
                   4395:     } else {
                   4396:         $r->print('<input type="hidden" name="cloning" value="none" />');
                   4397:     }
                   4398: 
                   4399: #
                   4400: # Table of cloneable textbook courses
                   4401: #
                   4402:     if (keys(%ordered)) {
                   4403:         $r->print('<div id="showtextbook" style="display:none">'.
                   4404:                   &Apache::loncommon::start_data_table().
                   4405:                   &Apache::loncommon::start_data_table_header_row().
                   4406:                   '<th>'.&mt('Title').'</th>'.
                   4407:                   '<th>'.&mt('Author(s)').'</th>'.
                   4408:                   '<th>'.&mt('Subject').'</th>'.
                   4409:                   '<th>'.&mt('Book').'</th>'.
                   4410:                   &Apache::loncommon::end_data_table_header_row());
                   4411:         my @items = sort { $a <=> $b } keys(%ordered);
                   4412:         foreach my $num (@items) {
                   4413:             my $item = $ordered{$num};
                   4414:             my $cleantitle=&HTML::Entities::encode($bookshash->{$item}->{'title'},'<>&"');
                   4415:             $cleantitle=~s/'/\\'/g;
                   4416:             $cleantitle =~ s/^\s+//;
                   4417:             $r->print(&Apache::loncommon::start_data_table_row().
                   4418:                       '<td><label><input type="radio" name="book" value="'.$item.'" />'.
                   4419:                       $cleantitle.'</label></td>'.
                   4420:                       '<td>'.$bookshash->{$item}->{'author'}.'</td>'.
                   4421:                       '<td>'.$bookshash->{$item}->{'subject'}.'</td>'.
                   4422:                       '<td><img border="0" src="'.$bookshash->{$item}->{'image'}.
                   4423:                       '" alt="'.$cleantitle.'" /></td>'. 
                   4424:                       &Apache::loncommon::end_data_table_row());
                   4425:         }
                   4426:         $r->print(&Apache::loncommon::end_data_table().
                   4427:                   '</div>');
                   4428:     }
                   4429: 
                   4430: #
                   4431: # Table of user's current courses (owner and/or course coordinator)
                   4432: #
                   4433:     if (keys(%cloneable)) {
                   4434:         my %lt = &clone_text();
                   4435:         $r->print('<div id="showexisting" style="display:none">'.
                   4436:                   &Apache::loncommon::start_data_table().
                   4437:                   &Apache::loncommon::start_data_table_header_row().
                   4438:                   '<th>'.&mt('Title').'</th>'.
                   4439:                   '<th>'.&mt('Owner/co-owner(s)').'</th>'.
                   4440:                   &Apache::loncommon::end_data_table_header_row());
                   4441:         my %allownernames;
                   4442:         my %sortbytitle; 
                   4443:         foreach my $cid (sort(keys(%cloneable))) {
                   4444:             if (ref($cloneable{$cid}) eq 'HASH') {
                   4445:                 my $cdesc = $cloneable{$cid}{'description'};
                   4446:                 $cdesc =~ s/`/'/g;
                   4447:                 if ($cdesc ne '') {
                   4448:                     push(@{$sortbytitle{$cdesc}},$cid);
                   4449:                 }
                   4450:             }
                   4451:          }
                   4452:          foreach my $title (sort(keys(%sortbytitle))) {
                   4453:              if (ref($sortbytitle{$title}) eq 'ARRAY') {
                   4454:                 foreach my $cid (sort(@{$sortbytitle{$title}})) {
                   4455:                     my $cleantitle=&HTML::Entities::encode($title,'<>&"');
                   4456:                     $cleantitle=~s/'/\\'/g;
                   4457:                     $cleantitle =~ s/^\s+//;
                   4458:                     my ($namestr,@owners,%ownernames);
                   4459:                     my $singleowner = $cloneable{$cid}{'internal.courseowner'};
                   4460:                     push(@owners,$singleowner);
                   4461:                     if ($cloneable{$cid}{'co-owners'} ne '') {
                   4462:                         foreach my $item (split(/,/,$cloneable{$cid}{'internal.co-owners'})) {
                   4463:                             push(@owners,$item);
                   4464:                         }
                   4465:                     }
                   4466:                     foreach my $owner (@owners) {
                   4467:                         my ($ownername,$ownerdom);
                   4468:                         if ($owner =~ /:/) {
                   4469:                             ($ownername,$ownerdom) = split(/:/,$owner);
                   4470:                         } else {
                   4471:                             $ownername = $owner;
                   4472:                             if ($owner ne '') {
                   4473:                                 $ownerdom = $dom;
                   4474:                             }
                   4475:                         }
                   4476:                         if ($ownername ne '' && $ownerdom ne '') {
                   4477:                             if (exists($allownernames{$ownername.':'.$ownerdom})) {
                   4478:                                 $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom}; 
                   4479:                             } else {
                   4480:                                 my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
                   4481:                                 $ownernames{$ownername.':'.$ownerdom} = \%namehash;
                   4482:                                 $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
                   4483:                             }
                   4484:                         }
                   4485:                     }
                   4486:                     my @lastnames;
                   4487:                     foreach my $owner (keys(%ownernames)) {
                   4488:                         if (ref($ownernames{$owner}) eq 'HASH') {
                   4489:                             push(@lastnames,$ownernames{$owner}{'lastname'});
                   4490:                         }
                   4491:                     }
                   4492:                     if (@lastnames) {
                   4493:                         $namestr = join(', ',sort(@lastnames));
                   4494:                     }
                   4495:                     $r->print(&Apache::loncommon::start_data_table_row().
                   4496:                               '<td><label><input type="radio" name="owned" value="'.$cid.'" />'.
                   4497:                               '&nbsp'.$cleantitle.'</label></td>'.
                   4498:                               '<td>'.$namestr.'</td>'.
                   4499:                               &Apache::loncommon::end_data_table_row());
                   4500:                 }
                   4501:             }
                   4502:         }
                   4503:         $r->print(&Apache::loncommon::end_data_table().
                   4504:               '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
                   4505:               '</label><br /><label>'.
                   4506:               '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
                   4507:               '</label><br /><label>'.
                   4508:               '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
                   4509:               $lt{'shd'}.'</label>'.
                   4510:               '<input type="text" size="5" name="dateshift" value="365" />'.
                   4511:               '</div>');
                   4512:     }
                   4513: #
                   4514: # End of content selector
                   4515: #
                   4516:     if (keys(%cloneable) || keys(%ordered)) {
                   4517:         $r->print('</fieldset></div>');
                   4518:     }
                   4519: 
                   4520:     my %accesstitles = (
                   4521:                           'start' => 'Default start access',
                   4522:                            'end'   => 'Default end access',
                   4523:                        );
                   4524:     my %help_item = (
                   4525:                        start => 'Course_Request_Access_Start',
                   4526:                        end   => 'Course_Request_Access_End',
                   4527:                     );
                   4528:     my $starttime = time;
                   4529:     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                   4530:     my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart',
                   4531:                                                         $starttime,'','','',1,'','','',1);
                   4532:     my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend',
                   4533:                                                       $endtime,'','','',1,'','','',1);
                   4534: #
                   4535: # Set default start and end dates for student access
                   4536: # 
                   4537:     $r->print('<div>'.
                   4538:               '<fieldset><legend>'.&mt('Student Access Dates').'</legend>'.
                   4539:               &Apache::loncommon::help_open_topic($help_item{'start'}).
                   4540:               '&nbsp;'.&mt($accesstitles{'start'}).$startform.'<br />'.
                   4541:               &Apache::loncommon::help_open_topic($help_item{'end'}).
                   4542:               '&nbsp;'.&mt($accesstitles{'end'}).$endform.'<br /></div>');
                   4543: 
                   4544: #
1.73      raeburn  4545: # Display any custom fields for this course type
                   4546: #
                   4547:     my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                   4548:                                                  $env{'user.domain'});
                   4549:     my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
                   4550:                                                           $env{'user.name'},
                   4551:                                                           $env{'user.domain'},$fullname);
                   4552:     if (ref($postprocess) eq 'HASH') {
                   4553:         if ($postprocess->{'reviewweb'}) {
                   4554:             $r->print($postprocess->{'reviewweb'});
                   4555:         }
                   4556:     }
                   4557: 
                   4558: #
1.72      raeburn  4559: # Submit button
                   4560: #
1.73      raeburn  4561:     $r->print('<input type="hidden" name="crstype" value="textbook" />'.
                   4562:               '<input type="hidden" name="action" value="process" />'.
1.72      raeburn  4563:               '<input type="submit" value="'.&mt('Create course').'" />');
                   4564: 
                   4565: #
                   4566: # End request form
                   4567: #
1.73      raeburn  4568:     $r->print('</form>');
                   4569:     &endContentScreen($r).
                   4570:     $r->print(&Apache::loncommon::end_page());
1.72      raeburn  4571:     return;
                   4572: }
                   4573: 
                   4574: sub process_textbook_request {
1.73      raeburn  4575:     my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_;
1.72      raeburn  4576:     my ($uniquecode,$req_notifylist);
                   4577:     my $crstype = 'textbook';
                   4578:     if (ref($domconfig) eq 'HASH') {
                   4579:         if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
                   4580:             if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') {
                   4581:                 $req_notifylist = $domconfig->{'requestcourses'}{'notify'}{'approval'};
                   4582:             }
                   4583:             if (ref($domconfig->{'requestcourses'}{'uniquecode'}) eq 'HASH') {
                   4584:                 $uniquecode = $domconfig->{'requestcourses'}{'uniquecode'}{$crstype};
                   4585:             }
                   4586:         }
                   4587:     }
                   4588:     my $crstype = 'textbook';
                   4589:     my $now = time;
                   4590:     my $reqtype = $env{'form.cloning'};
                   4591:     my (@inststatuses,$storeresult,$creationresult);
                   4592:     my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course');
                   4593:     my ($clonefrom,$clonedom,$clonecrs);
                   4594:     if ($reqtype eq 'textbook') {
                   4595:         $clonefrom = $env{'form.book'};
                   4596:     } elsif ($reqtype eq 'existing') {
                   4597:         $clonefrom = $env{'form.owned'};
                   4598:     }
                   4599:     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
                   4600:     if ($clonefrom) {
                   4601:         ($clonedom,$clonecrs) = split(/_/,$clonefrom);
                   4602:         if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') {
                   4603:             my $canclone =
                   4604:                 &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
                   4605:                             $env{'user.domain'},$clonecrs,$clonedom,$crstype);
                   4606:             unless ($canclone) {
                   4607:                 undef($clonecrs);
                   4608:                 undef($clonedom);
                   4609:             }
                   4610:         } else {
                   4611:             undef($clonecrs);
                   4612:             undef($clonedom);
                   4613:         }
                   4614:     }
                   4615:     $r->print(&header('Course Creation'));
                   4616: 
1.73      raeburn  4617:     if (ref($can_request) eq 'HASH') {
                   4618:         unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
                   4619:             &Apache::lonhtmlcommon::add_breadcrumb(
                   4620:                 { href => '/adm/requestcourse',
                   4621:                   text => 'Pick action',
                   4622:                 });
                   4623:         }
                   4624:     }
1.72      raeburn  4625:     &Apache::lonhtmlcommon::add_breadcrumb(
                   4626:                                            { href => '/adm/requestcourse',
                   4627:                                              text => "Create Course",
                   4628:                                            }
                   4629:                                           );
                   4630:     &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
                   4631:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
1.73      raeburn  4632:     &startContentScreen($r,'textbookrequests');
1.72      raeburn  4633: 
                   4634:     my $details = {
                   4635:                     owner          => $env{'user.name'},
                   4636:                     domain         => $env{'user.domain'},
                   4637:                     cdom           => $dom,
                   4638:                     cnum           => $cnum,
                   4639:                     coursehome     => $env{'form.chome'},
                   4640:                     cdescr         => $env{'form.cdescr'},
                   4641:                     crstype        => $crstype,
                   4642:                     uniquecode     => $uniquecode,
                   4643:                     clonedom       => $clonedom,
                   4644:                     clonecrs       => $clonecrs,
                   4645:                     accessstart    => $accessstart,
                   4646:                     accessend      => $accessend,
                   4647:                     personnel      => {},
                   4648:                   };
                   4649:     if ($reqtype eq 'existing') {
                   4650:         $details->{datemode} = $env{'form.datemode'};
                   4651:         $details->{dateshift} = $env{'form.dateshift'};
                   4652:     }
                   4653:     my ($result,$output) = &process_request($dom,$cnum,$crstype,$now,$details,'',$req_notifylist,[],$domconfig);
                   4654:     $r->print($output);
                   4655:     if (&Apache::loncoursequeueadmin::author_prompt()) {
                   4656:         &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
                   4657:     } elsif ($result eq 'created') {
                   4658:         $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
                   4659:     }
1.73      raeburn  4660:     &endContentScreen($r);
1.72      raeburn  4661:     $r->print(&Apache::loncommon::end_page());
                   4662: }
                   4663: 
                   4664: sub textbook_request_javascript {
                   4665:     my ($numbook,$numcurrent) = @_;
                   4666:     my %lt = &Apache::lonlocal::texthash(
                   4667:                  choose   => 'Please select a content option.',
                   4668:                  textbook => 'Please select a textbook, or choose a different option.',
                   4669:                  existing => 'Please select one of your existing courses to copy, or choose a different option.',
                   4670:                  title    => 'Please enter a course title.',
                   4671:              );
                   4672:     return if (!$numbook && !$numcurrent);
                   4673:     return <<"ENDSCRIPT";
                   4674: function cloneChoice() {
                   4675:     if (document.requestcourse.cloning) {
                   4676:         var radioLength = document.requestcourse.cloning.length;
                   4677:         if (radioLength == undefined) {
                   4678:             var val = document.requestcourse.cloning.value;
                   4679:             if ((val == 'textbook') || (val == 'existing')) {
                   4680:                 var elem = document.getElementById('show'+val);
                   4681:                 if (document.requestcourse.cloning.checked) {
                   4682:                     elem.style.display = 'block';
                   4683:                 } else {
                   4684:                     uncheckRadio(val);
                   4685:                     elem.style.display = 'none';
                   4686:                 }
                   4687:             }
                   4688:         } else {
                   4689:             for (var i=0; i<radioLength; i++) {
                   4690:                 var val = document.requestcourse.cloning[i].value;
                   4691:                 if ((val == 'textbook') || (val == 'existing')) {
                   4692:                     var elem = document.getElementById('show'+val);
                   4693:                     if (document.requestcourse.cloning[i].checked) {
                   4694:                         elem.style.display = 'block';
                   4695:                     }  else {
                   4696:                         if (val == 'textbook') {
                   4697:                             uncheckRadio('book');
                   4698:                         }
                   4699:                         if (val == 'existing') {
                   4700:                             uncheckRadio('owned');
                   4701:                         }
                   4702:                         elem.style.display = 'none';
                   4703:                     }
                   4704:                 }
                   4705:             }
                   4706:         }
                   4707:     }
                   4708:     return;
                   4709: }
                   4710: 
                   4711: function uncheckRadio(radioGroupName) {
                   4712:     var group = document.getElementsByName(radioGroupName);
                   4713:     var radioLength = group.length;
                   4714:     if (radioLength == undefined) {
                   4715:         group.checked = false;
                   4716:     } else {
                   4717:         for (var i=0; i<radioLength; i++) {
                   4718:             group[i].checked = false;
                   4719:         }
                   4720:     }
                   4721:     return;
                   4722: }
                   4723: 
                   4724: function uncheckAllRadio() {
                   4725:     uncheckRadio('cloning');
                   4726:     var numbook = $numbook;
                   4727:     var numcurrent = $numcurrent;
                   4728:     if (numbook > 0) {
                   4729:         uncheckRadio('textbook'); 
                   4730:     }
                   4731:     if (numcurrent > 0) {
                   4732:         uncheckRadio('existing');
                   4733:     }
                   4734:     return;
                   4735: }
                   4736: 
                   4737: function validTextbookReq() {
                   4738:     if (document.requestcourse.cloning) {
                   4739:         var cloneChoice = 0;
                   4740:         var radioLength = document.requestcourse.cloning.length;
                   4741:         if (radioLength == undefined) {
                   4742:             if (document.requestcourse.cloning.checked == false) {
                   4743:                 alert("$lt{'choose'}");
                   4744:                 return false;
                   4745:             } else {
                   4746:                 cloneChoice = document.requestcourse.cloning.value;
                   4747:             }
                   4748:         } else {
                   4749:             for (var i=0; i<radioLength; i++) {
                   4750:                 if (document.requestcourse.cloning[i].checked) {
                   4751:                     cloneChoice = document.requestcourse.cloning[i].value;
                   4752:                     break;
                   4753:                 }
                   4754:             }
                   4755:             if (cloneChoice == 0) {
                   4756:                 alert("$lt{'choose'}");
                   4757:                 return false;
                   4758:             }
                   4759:         }
                   4760:         var group;
                   4761:         if ((cloneChoice == 'textbook') || (cloneChoice == 'existing')) {
                   4762:             var group;
                   4763:             if (cloneChoice == 'textbook') {
                   4764:                 group = document.getElementsByName('book');
                   4765:             } else {
                   4766:                 group = document.getElementsByName('owned');
                   4767:             }
                   4768:             var groupLength = group.length;
                   4769:             var chosen = 0;
                   4770:             if (groupLength == undefined) {
                   4771:                 if (group.checked) {
                   4772:                     chosen = 1;
                   4773:                 }
                   4774:             } else {
                   4775:                 for (var j=0; j<groupLength; j++) {
                   4776:                     if (group[j].checked) {
                   4777:                         chosen = 1;
                   4778:                         break;
                   4779:                     }
                   4780:                 }
                   4781:            }
                   4782:            if (chosen == 0) {
                   4783:                if (cloneChoice == 'textbook') {
                   4784:                    alert("$lt{'textbook'}");
                   4785:                } else {
                   4786:                    alert("$lt{'existing'}");
                   4787:                }
                   4788:                return false;
                   4789:             }
                   4790:         }
                   4791:     }
                   4792:     if (document.requestcourse.cdescr.value == '') {
                   4793:         alert("$lt{'title'}");
                   4794:         return false;
                   4795:     }
                   4796:     return true;
                   4797: }
                   4798:  
                   4799: ENDSCRIPT
                   4800: 
                   4801: }
1.73      raeburn  4802: 
                   4803: sub startContentScreen {
                   4804:     my ($r,$mode)=@_;
                   4805:     $r->print("\n".'<ul class="LC_TabContentBigger" id="textbookreq">'."\n");
                   4806:     $r->print('<li'.(($mode eq 'textbookrequests')?' class="active"':'').'><a href="/adm/requestcourse"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Request a Course').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n");
                   4807:     $r->print('<li'.(($mode eq 'textbooklogs')?' class="active"':'').'><a href="/adm/requestcourse?action=log&amp;crstype=textbook&amp;tabs=on"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Course Request History').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n");
                   4808:     $r->print("\n".'</ul>'."\n");
                   4809:     $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="mainbox" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="maincontentbox" style="display: block;">');
                   4810: }
                   4811: 
                   4812: sub endContentScreen {
                   4813:    my ($r)=@_;
                   4814:    $r->print('</div></div></div>');
                   4815: }
1.72      raeburn  4816:    
1.1       raeburn  4817: 1;
                   4818: 

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