File:  [LON-CAPA] / loncom / interface / lonrequestcourse.pm
Revision 1.95.2.7.2.3: download - view: text, annotated - select for diffs
Sat Mar 11 04:54:24 2023 UTC (15 months ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.95.2.7: preferred, unified
- For 2.11.4 (modified)
  Include changes in rev. 1.116

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

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