Annotation of loncom/automation/batchcreatecourse.pm, revision 1.45

1.4       albertel    1: #
1.45    ! raeburn     2: # $Id: batchcreatecourse.pm,v 1.44 2020/05/22 15:05:36 raeburn Exp $
1.4       albertel    3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
                     26: 
1.1       raeburn    27: package LONCAPA::batchcreatecourse;
                     28: use LONCAPA::Configuration;
                     29: use LONCAPA::Enrollment;
                     30: use HTML::Parser;
                     31: use Time::Local;
                     32: use Apache::lonnet;
1.2       raeburn    33: use Apache::loncommon;
1.1       raeburn    34: use Apache::lonlocal;
1.21      raeburn    35: use LONCAPA qw(:match);
1.1       raeburn    36: 
1.9       raeburn    37: use strict;
                     38: 
1.1       raeburn    39: # Collection of routines used for batch creation of courses and users.
                     40: # &create_courses() should be called by an Autocreate.pl
                     41: # script via a cron entry, or alternatively from a web page, after upload 
                     42: # of a file containing an XML description of a course request (lonbatchccrs.pm).
                     43: # 
                     44: # XML file(s) describing courses that are to be created in domain $dom are stored in
1.3       raeburn    45: # /home/httpd/perl/tmp/addcourse/$dom
1.1       raeburn    46: #
                     47: # &create_courses() will create an account for the course owner 
                     48: # (if one does not currently exist), will create the course (cloning if necessary),
                     49: # and will add additional instructional staff (creating accounts if necessary).
                     50: #
                     51: # Example of XML file (which could contain more than one class to be created):
                     52: #
                     53: #<?xml version="1.0" encoding="UTF-8"?>
                     54: #<!DOCTYPE text>
                     55: #<class id="ss05ubw101">
                     56: # <title>Underwater Basket Weaving</title>
1.16      raeburn    57: # <crstype>Course</crstype>
1.1       raeburn    58: # <coursecode>ss05ubw101</coursecode>
1.38      raeburn    59: # <defaultcredits>3</defaultcredits>
1.1       raeburn    60: # <coursehome>msul1</coursehome>
                     61: # <coursedomain>msu</coursedomain>
                     62: # <reshome>/res/msu/</reshome>
                     63: # <optional_id></optional_id>
                     64: # <adds>1</adds>
                     65: # <drops>1</drops>
                     66: # <enrollstart>2005:01:04:10:30</enrollstart>
                     67: # <enrollend>2005:07:04:20:30</enrollend>
                     68: # <accessstart>2005:01:10:10:30</accessstart>
                     69: # <accessend>2005:05:31:10:30</accessend>
                     70: # <authentication>
                     71: #  <method>krb4</method>
                     72: #  <param>MSU.EDU</param>
                     73: # </authentication>
                     74: # <nonstandard></nonstandard>
                     75: # <topmap></topmap>
                     76: # <firstres>nav</firstres>
1.15      raeburn    77: # <crsquota>20</crsquota>
1.39      raeburn    78: # <uniquecode>1</uniquecode>
1.1       raeburn    79: # <clonecrs>466011437c34194msul1</clonecrs>
                     80: # <clonedom>msu</clonedom>
1.27      raeburn    81: # <datemode>shift</datemode>
                     82: # <dateshift>365</dateshift>
1.45    ! raeburn    83: # <tinyurls>create</tinyurls>
1.1       raeburn    84: # <showphotos></showphotos>
                     85: # <setpolicy>1</setpolicy>
                     86: # <setcontent>1</setcontent>
1.42      raeburn    87: # <setcomment>1</setcomment>
1.1       raeburn    88: # <setkeys>0</setkeys>
1.19      albertel   89: # <keyauth>keyadmin:msu</keyauth>
1.1       raeburn    90: # <disresdis>1</disresdis>
                     91: # <disablechat>1</disablechat>
                     92: # <openall></openall>
1.44      raeburn    93: # <openallfrom></openallfrom>
1.1       raeburn    94: # <notify_dc>1</notify_dc>
                     95: # <notify_owner>1</notify_owner>
                     96: # <owner>
                     97: #  <username>sparty</username>
                     98: #  <domain>msu</domain>
                     99: #  <authtype>krb4</authtype>
                    100: #  <autharg>MSU.EDU</autharg>
                    101: # </owner>
                    102: # <sections>
                    103: #  <section>
                    104: #   <inst>001</inst>
                    105: #   <loncapa>1</loncapa>
                    106: #  </section>
                    107: #  <section>
                    108: #   <inst>002</inst>
                    109: #   <loncapa>2</loncapa>
                    110: #  </section>
                    111: # </sections>
                    112: # <crosslists>
                    113: #  <xlist>
                    114: #   <inst>ss05zzz101001</inst>
                    115: #   <loncapa>1</loncapa>
                    116: #  </xlist>
                    117: # </crosslists>
                    118: # <users>
                    119: #  <user>
                    120: #   <username>sparty</username>
                    121: #   <domain>msu</domain>
                    122: #   <email>sparty@msu.edu</email>
                    123: #   <authtype>krb4</authtype>
                    124: #   <autharg></autharg>
                    125: #   <firstname>MSU</firstname>
                    126: #   <generation></generation>
                    127: #   <lastname>Spartan</lastname>x
                    128: #   <middlename></middlename>
                    129: #   <studentID></studentID>
1.38      raeburn   130: #   <credits></credits>
1.1       raeburn   131: #   <roles></roles>
                    132: #  </user>
                    133: #  <user>
                    134: #   <username>itds0001</username>
                    135: #   <domain>northwood5</domain>
                    136: #   <email>itds0001@msu.edu</email>
                    137: #   <authtype>int</authtype>
                    138: #   <autharg></autharg>
                    139: #   <firstname>Info</firstname>
                    140: #   <generation></generation>
                    141: #   <lastname>Techc</lastname>x
                    142: #   <middlename></middlename>
                    143: #   <studentID></studentID>
                    144: #   <roles>
                    145: #    <role id='in'>
                    146: #     <start>2005:01:01:12:10</start>
                    147: #     <end>2005:12:01:12:10</end>
                    148: #     <usec>1</usec>
                    149: #     <usec>2</usec>
                    150: #    </role>
                    151: #   </roles>
                    152: #  </user>
                    153: # </users>
                    154: #</class>
                    155: #
                    156: # Many of these are binary options (corresponding to either checkboxes or
                    157: # radio buttons in the interactive CCRS page).  Examples include:
1.42      raeburn   158: # setpolicy, setcontent, setcomment, setkeys, disableresdis, disablechat, openall,
1.39      raeburn   159: # uniquecode
1.1       raeburn   160: #
                    161: # A value of 1 between opening and closing tags is equivalent to a 
                    162: # checked checkbox or 'Yes' response in the original CCRS web page.
                    163: # A value of 0 or blank is equivalent to an unchecked box or 'No'
                    164: # response. Dates are in format YYYY:MM:DD:HH:MM:SS (:separators required)
                    165: #
1.15      raeburn   166: # firstres can be nav, syl, or blank for "Navigate Contents", Syllabus, or
1.1       raeburn   167: # no entry respectively.
1.15      raeburn   168: # 
1.41      raeburn   169: # crstype can be Course, Community or Placement
1.15      raeburn   170: #
                    171: # crsquota is the total disk space permitted for course group portfolio files
                    172: # in all course groups.
                    173: # 
1.1       raeburn   174: # For format of other parameters, refer to the interactive CCRS page
                    175: # and view how the equivalent parameter is displayed in the web form.  
                    176: #  
                    177: ##############################################################
                    178: # create_courses() - creates courses described in @$requests,
                    179: #                    files listed in @$requests are deleted
                    180: #                    after the files have been parsed.
                    181: #
1.3       raeburn   182: #                    Directory for retrieval of files listed in @$requests is: 
                    183: #                    /home/httpd/perl/tmp/addcourse/$dom/auto/pending if $context = auto
1.13      raeburn   184: #                    /home/httpd/perl/tmp/addcourse/$dom/web/$uname_$udom/pending if $context = web
1.1       raeburn   185: #                    
1.39      raeburn   186: # inputs (six)   -  requests - ref to array of filename(s) containing course requests 
1.1       raeburn   187: #                   courseids - ref to hash to store LON-CAPA course ids of new courses 
                    188: #                   context - auto if called from command line, web if called from browser
                    189: #                   dom - domain for which the course is being created
1.3       raeburn   190: #                   uname - username of DC who is requesting course creation
                    191: #                   udom - domain of DC who is requesting course creation
1.1       raeburn   192: #  
1.45    ! raeburn   193: # outputs (six)  -  output - text recording user roles added etc.
        !           194: #                   logmsg - text to be logged
        !           195: #                   cloneinfo - text output from cloning
        !           196: #                   keysmsg - text containing link(s) to manage keys page(s) 
        !           197: #                   codehash - reference to hash containing courseID => unique code
        !           198: #                              where unique code is a 6 character code, to distribute
        !           199: #                              to students as a shortcut to the course.
        !           200: #                   instcodes - references to hash of an array, where keys are
        !           201: #                               institutional codes and values are an array of
        !           202: #                               courseIDs of courses with that code.
1.1       raeburn   203: #############################################################
                    204: 
                    205: sub create_courses {
1.3       raeburn   206:     my ($requests,$courseids,$context,$dom,$uname,$udom) = @_;
1.1       raeburn   207:     my $output;
                    208:     my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
                    209: # Get role names
                    210:     my %longroles = ();
1.9       raeburn   211:     open(FILE,"<$$perlvarref{'lonTabDir'}.'/rolesplain.tab");
1.1       raeburn   212:     my @rolesplain = <FILE>;
                    213:     close(FILE);
1.32      raeburn   214:     foreach my $item (@rolesplain) {
                    215:         if ($item =~ /^(st|ta|ep|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
                    216:             $longroles{'Course'}{$1} = $2;
                    217:             $longroles{'Community'}{$1} = $3;
1.1       raeburn   218:         }
                    219:     }
1.45    ! raeburn   220:     my ($logmsg,$cloneinfo,$keysmsg,$newusermsg,$addresult,$user_lh,
        !           221:         %codehash,%instcodes);
1.1       raeburn   222:     my %enrollcount = ();
1.37      foxr      223:     my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context;
1.3       raeburn   224:     if ($context eq 'auto') {
1.45    ! raeburn   225:         $user_lh = &Apache::loncommon::user_lang($uname,$udom);
1.3       raeburn   226:         $newcoursedir .= '/pending';
                    227:     } else {
                    228:         if ($uname && $udom) {
1.13      raeburn   229:             $newcoursedir .= '/'.$uname.'_'.$udom.'/pending';
1.3       raeburn   230:         } else {
                    231:             $logmsg = "batchcreatecourse::create_courses() called without username and/or domain of requesting Domain Coordinator";
1.1       raeburn   232:         }
                    233:     }
                    234:     if (@{$requests} > 0) {
                    235:         foreach my $request (@{$requests}) {
                    236:             my %details = ();
1.45    ! raeburn   237:             my $clonemsg = [];
1.1       raeburn   238:             if (-e $newcoursedir.'/'.$request) {
                    239:                 &parse_coursereqs($newcoursedir.'/'.$request, \%details);
1.29      raeburn   240:                 foreach my $num (sort(keys(%details))) {
                    241:                     my $reqdetails = $details{$num};
1.39      raeburn   242:                     my $code;
1.45    ! raeburn   243:                     my $courseid =
        !           244:                         &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,
        !           245:                                       $clonemsg,\$newusermsg,\$addresult,\%enrollcount,
        !           246:                                       \$output,\$keysmsg,undef,undef,undef,undef,\$code);
1.25      raeburn   247:                     if ($courseid =~m{^/$match_domain/$match_courseid}) {
1.21      raeburn   248:                         $$courseids{$courseid} = $details{$num}{'class'};
1.39      raeburn   249:                         if ($code) {
                    250:                             $codehash{$courseid} = $code;
                    251:                         }
1.43      raeburn   252:                         if ($details{$num}{'coursecode'} ne '') {
                    253:                             push(@{$instcodes{$details{$num}{'coursecode'}}},$courseid);
                    254:                         }
1.21      raeburn   255:                     }
1.45    ! raeburn   256:                     if (@{$clonemsg}) {
        !           257:                         if ($context eq 'web') {
        !           258:                             $cloneinfo .= '<p class="LC_info">';
        !           259:                         }
        !           260:                         foreach my $item (@{$clonemsg}) {
        !           261:                             if (ref($item) eq 'HASH') {
        !           262:                                 if ($context eq 'auto') {
        !           263:                                     $cloneinfo .= &mt_user($user_lh,$item->{mt},
        !           264:                                                            @{$item->{args}});
        !           265:                                 } else {
        !           266:                                     $cloneinfo .= &mt($item->{mt},@{$item->{args}});
        !           267:                                 }
        !           268:                             }
        !           269:                             if ($context eq 'web') {
        !           270:                                 $cloneinfo .= '<br />';
        !           271:                             }
        !           272:                             $cloneinfo .= "\n";
        !           273:                         }
        !           274:                         if ($context eq 'web') {
        !           275:                             $cloneinfo .= '</p>';
        !           276:                         }
        !           277:                     }
1.1       raeburn   278:                 }
                    279:             }
                    280:         }
                    281:     }
1.45    ! raeburn   282:     return ($output,$logmsg,$cloneinfo,$keysmsg,\%codehash,\%instcodes);
1.1       raeburn   283: }
                    284: 
                    285: #############################################################
                    286: #
                    287: # parse_coursereqs() 
                    288: # inputs (two) - coursefile - path to XML file containing course(s) to be created.
                    289: #              - details - reference to hash containing extracted information.
                    290: # outputs (none)
                    291: #
                    292: ############################################################
                    293: 
                    294: sub parse_coursereqs {
                    295:     my ($coursefile,$details) = @_;
                    296: #   Note all start and end dates should be in this format:
                    297: #   YYYY:MM:DD:HH:MM:SS (:separators required).
                    298:     my $uname = '';
                    299:     my @state = ();
                    300:     my $num = 0;
                    301:     my $secid = 0;
                    302:     my $xlist = 0;
                    303:     my $userkey = '';
                    304:     my $role = '';
1.45    ! raeburn   305:     my @items = ('title','optional_id','coursecode','defaultcredits','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','tinyurls','showphotos','setpolicy','setcontent','setcomment','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota','uniquecode');
1.33      raeburn   306:     my @possroles = qw(st ad ep ta in cc co);
1.44      raeburn   307:     my @dateitems = ('enrollstart','enrollend','accessstart','accessend','openallfrom');
1.1       raeburn   308:     my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');
                    309:     my $p = HTML::Parser->new
                    310:     (
                    311:         xml_mode => 1,
                    312:         start_h =>
                    313:             [sub {
                    314:                  my ($tagname, $attr) = @_;
                    315:                  push(@state, $tagname);
                    316:                  if ("@state" eq "class") {
                    317:                      %{$$details{$num}} = ();
                    318:                      $$details{$num}{'class'} = $attr->{id};
                    319:                      %{$$details{$num}{'users'}} = ();
                    320:                      %{$$details{$num}{'sections'}} = ();
                    321:                      $secid = 0;
                    322:                      $xlist = 0;
                    323:                  }
                    324:                  if ("@state" eq "class users user roles role") {
                    325:                      $role = $attr->{id};
1.33      raeburn   326:                      if (grep(/^\Q$role\E$/,@possroles)) {
1.1       raeburn   327:                          push(@{$$details{$num}{'users'}{$userkey}{'roles'}}, $role);  
                    328:                          %{$$details{$num}{'users'}{$userkey}{$role}} = ();
                    329:                          @{$$details{$num}{'users'}{$userkey}{$role}{'usec'}} = ();
                    330:                      }
                    331:                  }
                    332:                  if ("@state" eq "class sections section") {
                    333:                      $secid ++;
                    334:                      %{$$details{$num}{'sections'}{$secid}} = ();
                    335:                  }
                    336:                  if ("@state" eq "class crosslists xlist") {
                    337:                      $xlist ++;
                    338:                      %{$$details{$num}{'crosslists'}{$xlist}} = ();
                    339:                  }
                    340:             }, "tagname, attr"],
                    341:          text_h =>
                    342:              [sub {
                    343:                  my ($text) = @_;
                    344:                  if ("@state" eq "class owner username") {
                    345:                      $$details{$num}{'owner'} = $text;
                    346:                  } elsif ("@state" eq "class owner domain") {
                    347:                     $$details{$num}{'domain'} = $text;
                    348:                  } elsif ("@state" eq "class sections section inst") {
                    349:                     $$details{$num}{'sections'}{$secid}{'inst'} = $text;
                    350:                  } elsif ("@state" eq "class sections section loncapa") {
                    351:                     $$details{$num}{'sections'}{$secid}{'loncapa'} = $text;
                    352:                  } elsif ("@state" eq "class crosslists xlist inst") {
                    353:                     $$details{$num}{'crosslists'}{$xlist}{'inst'} = $text;
                    354:                  } elsif ("@state" eq "class crosslists xlist loncapa") {
                    355:                     $$details{$num}{'crosslists'}{$xlist}{'loncapa'} = $text;
                    356:                  } elsif ("@state" eq "class owner authtype") {
                    357:                     $$details{$num}{'ownerauthtype'} = $text;
                    358:                  } elsif ("@state" eq "class owner autharg") {
1.5       raeburn   359:                     $$details{$num}{'ownerauthparam'} = $text;
1.1       raeburn   360:                  } elsif ("@state" eq "class authentication method") {
                    361:                     $$details{$num}{'authtype'} = $text;
                    362:                  } elsif ("@state" eq "class authentication param") {
                    363:                     $$details{$num}{'authparam'} = $text;
                    364:                  } elsif ("@state" eq "class users user username") {
                    365:                     $userkey = $text;
                    366:                  } elsif ("@state" eq "class users user domain") {
                    367:                     $userkey .= ':'.$text;
                    368:                     %{$$details{$num}{'users'}{$userkey}} = ();
                    369:                     @{$$details{$num}{'users'}{$userkey}{'roles'}} = ();
                    370:                  } elsif ("@state" eq "class users user email") {
                    371:                     $$details{$num}{'users'}{$userkey}{'emailaddr'} = $text;
1.35      bisitz    372:                     $$details{$num}{'users'}{$userkey}{'emailenc'} = &LONCAPA::escape($text); 
1.1       raeburn   373:                  } elsif ("@state" eq "class users user roles role start") {
1.33      raeburn   374:                      if (grep(/^\Q$role\E$/,@possroles)) {
1.1       raeburn   375:                          $$details{$num}{'users'}{$userkey}{$role}{'start'} = &process_date($text);
                    376:                      }
                    377:                  } elsif ("@state" eq "class users user roles role end") {
1.33      raeburn   378:                      if (grep(/^\Q$role\E$/,@possroles)) {
1.1       raeburn   379:                          $$details{$num}{'users'}{$userkey}{$role}{'end'} = &process_date($text);
                    380:                      }
                    381:                  } elsif ("@state" eq "class users user roles role usec") {
1.33      raeburn   382:                      if (grep(/^\Q$role\E$/,@possroles)) {
1.1       raeburn   383:                          unless ($text eq '') {
                    384:                              push(@{$$details{$num}{'users'}{$userkey}{$role}{'usec'}},$text);
                    385:                          }
                    386:                      }
                    387:                  } else {
                    388:                      foreach my $item (@items) {
                    389:                          if ("@state" eq "class $item") {
                    390:                              $$details{$num}{$item} = $text;
                    391:                          }
                    392:                      }
                    393:                      foreach my $item (@dateitems) {
                    394:                          if ("@state" eq "class $item") {
                    395:                              $$details{$num}{$item} = &process_date($text);
                    396:                          }
                    397:                      }
                    398:                      foreach my $item (@useritems) {
                    399:                          if ("@state" eq "class users user $item") {
                    400:                              $$details{$num}{'users'}{$userkey}{$item} = $text;
                    401:                          }
                    402:                      }
                    403:                  }
                    404:                }, "dtext"],
                    405:          end_h =>
                    406:                [sub {
                    407:                    my ($tagname) = @_;
                    408:                    if ("@state" eq "class") {
                    409:                        $num ++;
                    410:                    }
                    411:                    pop @state;
                    412:                 }, "tagname"],
                    413:     );
                    414: 
                    415:     $p->parse_file($coursefile);
                    416:     $p->eof;
                    417:     return;
                    418: }
                    419: 
                    420: #########################################################
                    421: #
                    422: # build_course() 
                    423: #
                    424: # inputs
1.28      raeburn   425: #   course domain
1.1       raeburn   426: #   course request number
                    427: #   context - auto if called from command line, web if called from DC web interface
                    428: #   ref to hash of course creation information
                    429: #   ref to hash of role descriptions
                    430: #   ref to scalar used to accumulate log messages
1.45    ! raeburn   431: #   ref to array used to accumulate messages about cloning
1.1       raeburn   432: #   ref to scalar used to accumulate messages sent to new users
                    433: #   ref to scalar used to accumulate results of new user additions
                    434: #   ref to hash of enrollment counts for different roles
1.28      raeburn   435: #   ref to scalar used to accumulate information about added roles
                    436: #   ref to scalar used to accumulate information about access keys
                    437: #   domain of DC creating course
                    438: #   username of DC creating course   
                    439: #   optional course number, if unique course number already obtained (e.g., for
1.39      raeburn   440: #       course requests submitted via course request form.
                    441: #   optional category
                    442: #   optional ref to scalar for six character unique identifier
1.45    ! raeburn   443: #   caller context (e.g., auto)
        !           444: #   user language handle, if caller context is 'auto'
1.1       raeburn   445: #
                    446: # outputs
                    447: #   LON-CAPA courseID for new (created) course
                    448: #
                    449: #########################################################
                    450: 
                    451: sub build_course {
1.45    ! raeburn   452:     my ($cdom,$num,$context,$details,$longroles,$logmsg,$clonemsg,$newusermsg,
        !           453:         $addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,
        !           454:         $coderef,$callercontext,$user_lh) = @_;
1.29      raeburn   455:     return unless (ref($details) eq 'HASH');
                    456:     my $owner_uname = $details->{'owner'};
                    457:     my $owner_domain = $details->{'domain'};
1.1       raeburn   458:     my $owner = $owner_uname.':'.$owner_domain;
                    459:     my $sectionstr = '';
                    460:     my $xliststr = '';
                    461:     my $noenddate = '';
                    462:     my $outcome;
1.32      raeburn   463:     my ($courseid,$crsudom,$crsunum,$crstype,$ccrole,$rolenames);
                    464:     if ($details->{'crstype'} eq 'Community') {
                    465:         $crstype = $details->{'crstype'};
                    466:         $ccrole ='co';
                    467:         if (ref($longroles) eq 'HASH') {
                    468:             $rolenames = $longroles->{'Community'};
                    469:         }
                    470:     } else {
1.41      raeburn   471:         if ($details->{'crstype'} eq 'Placement') {
                    472:             $crstype = $details->{'crstype'};
                    473:         } else {
                    474:             $crstype = 'Course';
                    475:         }
1.32      raeburn   476:         $ccrole = 'cc';
                    477:         if (ref($longroles) eq 'HASH') {
                    478:             $rolenames = $longroles->{'Course'};
                    479:         }
                    480:     }
1.1       raeburn   481:     my $linefeed;
                    482:     if ($context eq 'auto') {
                    483:         $linefeed = "\n";
                    484:     } else {
                    485:         $linefeed = "<br />\n";
                    486:     }
1.29      raeburn   487:     if ($details->{'accessend'} eq '') {
1.1       raeburn   488:         $noenddate = 1;
                    489:     }
1.29      raeburn   490:     my $reshome = $details->{'reshome'};
1.1       raeburn   491:     if ($reshome eq '') {
                    492:         $reshome = '/res/'.$cdom;
                    493:     }
1.29      raeburn   494:     my $firstres =  $details->{'firstres'};
1.1       raeburn   495:     if ($firstres eq '') {
1.36      raeburn   496:         if ($crstype eq 'Community') {
                    497:             $firstres = 'nav';
1.41      raeburn   498:         } elsif ($crstype eq 'Placement') {
                    499:             $firstres = 'blank'; 
1.36      raeburn   500:         } else {
                    501:             $firstres = 'syl';
                    502:         }
1.1       raeburn   503:     }
1.29      raeburn   504:     foreach my $secid (sort(keys(%{$details->{'sections'}}))) {
                    505:         $sectionstr .= $details->{'sections'}{$secid}{'inst'}.':'.$details->{'sections'}{$secid}{'loncapa'}.',';
1.1       raeburn   506:     }
1.5       raeburn   507:     $sectionstr =~ s/,$//;
1.1       raeburn   508: 
1.29      raeburn   509:     foreach my $xlist (sort(keys(%{$details->{'crosslists'}}))) {
                    510:         $xliststr .= $details->{'crosslists'}{$xlist}{'inst'}.':'.$details->{'crosslists'}{$xlist}{'loncapa'}.',';
1.1       raeburn   511:     }
1.5       raeburn   512:     $xliststr =~ s/,$//;
1.1       raeburn   513: 
                    514:     my %courseinfo = (
1.29      raeburn   515:                       inst_code => $details->{'coursecode'},
                    516:                       description => $details->{'title'}
1.1       raeburn   517:                      ); 
1.29      raeburn   518:     if (&Apache::lonnet::homeserver($details->{'owner'},$details->{'domain'}) eq 'no_host') { # Add user if no account
                    519:         my $ownerargs = {'auth' => $details->{'ownerauthtype'},
                    520:                     'authparam' => $details->{'ownerauthparam'},
                    521:                     'emailenc' => $details->{'emailenc'},
                    522:                     'udom' => $details->{'domain'},
                    523:                     'uname' => $details->{'owner'},
                    524:                     'pid' => $details->{'users'}{$owner}{'studentID'},
                    525:                     'first' => $details->{'users'}{$owner}{'firstname'},
                    526:                     'middle' => $details->{'users'}{$owner}{'middlename'},
                    527:                     'last' => $details->{'users'}{$owner}{'lastname'},
                    528:                     'gene' => $details->{'users'}{$owner}{'generation'},
1.1       raeburn   529:                     'usec' => '',
                    530:                     'end' => '',
                    531:                     'start' => '',
1.29      raeburn   532:                     'emailaddr' => $details->{'users'}{$owner}{'email'},
1.1       raeburn   533:                     'cid' => '',
                    534:                     'context' => 'createowner',
                    535:                     'linefeed' => $linefeed,
1.32      raeburn   536:                     'role' => $ccrole,
1.5       raeburn   537:                    };
1.32      raeburn   538:         $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$rolenames,\%courseinfo,$context);
1.1       raeburn   539:     } else {
                    540:         $outcome = 'ok';
                    541:     }
                    542: 
1.6       raeburn   543:     if ($outcome eq 'ok') {
1.29      raeburn   544:         if ($details->{'datemode'} !~ /^(preserve|shift|delete)$/) {
                    545:             $details->{'datemode'} = 'shift';
                    546:             $details->{'dateshift'} = 365;
1.27      raeburn   547:         }
1.45    ! raeburn   548:         if ($details->{'tinyurls'} !~ /^(delete|transfer|create)$/) {
        !           549:             $details->{'tinyurls'} = 'create';
        !           550:         }
1.6       raeburn   551:         my $courseargs = {
1.29      raeburn   552:                ccuname => $details->{'owner'},
                    553:                ccdomain => $details->{'domain'},
                    554:                cdescr => $details->{'title'},
                    555:                crstype => $details->{'crstype'},
                    556:                curl => $details->{'topmap'},
1.1       raeburn   557:                course_domain => $cdom,
1.29      raeburn   558:                course_home =>  $details->{'coursehome'},
                    559:                nonstandard => $details->{'nonstandard'},
                    560:                crscode => $details->{'coursecode'},
1.38      raeburn   561:                defaultcredits => $details->{'defaultcredits'},
1.29      raeburn   562:                crsquota => $details->{'crsquota'},
1.39      raeburn   563:                uniquecode => $details->{'uniquecode'},
1.29      raeburn   564:                clonecourse => $details->{'clonecrs'},
                    565:                clonedomain => $details->{'clonedom'},
                    566:                datemode => $details->{'datemode'},
                    567:                dateshift => $details->{'dateshift'},
1.45    ! raeburn   568:                tinyurls => $details->{'tinyurls'},
1.29      raeburn   569:                crsid => $details->{'optional_id'},
                    570:                curruser => $details->{'owner'},
1.1       raeburn   571:                crssections => $sectionstr,
                    572:                crsxlist => $xliststr,
1.29      raeburn   573:                autoadds => $details->{'adds'},
                    574:                autodrops => $details->{'drops'},
                    575:                notify => $details->{'notify_owner'},
                    576:                notify_dc => $details->{'notify_dc'},
1.1       raeburn   577:                no_end_date => $noenddate,
1.29      raeburn   578:                showphotos => $details->{'showphotos'},
                    579:                authtype => $details->{'authtype'},
                    580:                autharg => $details->{'authparam'},
                    581:                enrollstart => $details->{'enrollstart'},
                    582:                enrollend => $details->{'enrollend'},
                    583:                startaccess => $details->{'accessstart'},
                    584:                endaccess => $details->{'accessend'},
                    585:                setpolicy => $details->{'setpolicy'},
                    586:                setcontent => $details->{'setcontent'},
1.42      raeburn   587:                setcomment => $details->{'setcomment'},
1.1       raeburn   588:                reshome => $reshome,
1.29      raeburn   589:                setkeys => $details->{'setkeys'},
                    590:                keyauth => $details->{'keyauth'},
                    591:                disresdis => $details->{'disresdis'},
                    592:                disablechat => $details->{'disablechat'},
                    593:                openall => $details->{'openall'},
1.44      raeburn   594:                openallfrom => $details->{'openallfrom'},
1.1       raeburn   595:                firstres => $firstres
                    596:                };
1.40      raeburn   597:         if ($details->{'textbook'}) {
                    598:             $courseargs->{'textbook'} = $details->{'textbook'};
                    599:         }
1.20      albertel  600:         my %host_servers = &Apache::lonnet::get_servers($cdom,'library');
1.29      raeburn   601:         if (! exists($host_servers{$details->{'coursehome'}})) {
                    602:             $$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'};
1.1       raeburn   603:             return;
                    604:         }
1.45    ! raeburn   605:         my ($success,$msg,$cloneinfo) = 
1.39      raeburn   606:             &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,
1.45    ! raeburn   607:                                                  $udom,$uname,$context,$cnum,$category,$coderef,
        !           608:                                                  $callercontext,$user_lh);
1.23      albertel  609: 	$$logmsg .= $msg;
1.45    ! raeburn   610:         if ((ref($clonemsg) eq 'ARRAY') && (ref($cloneinfo) eq 'ARRAY')) {
        !           611:              push(@{$clonemsg},@{$cloneinfo});
        !           612:         }
1.24      raeburn   613:         if (!$success) {
                    614:             return;
                    615:         }
1.1       raeburn   616:     } else {
                    617:         return;
                    618:     }
1.43      raeburn   619: 
1.1       raeburn   620: #
1.32      raeburn   621: # Make owner a coordinator
1.1       raeburn   622: #
                    623:     if (($owner_domain) && ($owner_uname)) {
1.32      raeburn   624:         &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,$ccrole,'','','','',$context);
1.1       raeburn   625:     }
                    626: 
                    627: #
                    628: # Process other reqested users
                    629: #
1.32      raeburn   630: 
                    631:     my @courseroles = qw(st ep ta in);
                    632:     push(@courseroles,$ccrole);
1.31      raeburn   633:     if (&owner_is_dc($owner_uname,$owner_domain,$crsudom)) {
                    634:         push(@courseroles,'ad');
                    635:     }
1.1       raeburn   636:     my $stulogmsg = '';
1.29      raeburn   637:     foreach my $userkey (sort(keys(%{$details->{'users'}}))) {
1.1       raeburn   638:         my $url = '/'.$crsudom.'/'.$crsunum;
1.29      raeburn   639:         next if (ref($details->{'users'}{$userkey}{'roles'}) ne 'ARRAY');   
                    640:         if (@{$details->{'users'}{$userkey}{'roles'}} > 0) {
1.1       raeburn   641:             my ($username,$userdom) = split/:/,$userkey;
                    642:             if (&Apache::lonnet::homeserver($username,$userdom) eq 'no_host') { # Add user if no account
1.31      raeburn   643:                 my @reqroles = @{$details->{'users'}{$userkey}{'roles'}};
                    644:                 my @badroles;
                    645:                 my $firstrole = shift(@reqroles);
                    646:                 while (@reqroles > 0) { 
                    647:                     if ($firstrole =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
                    648:                         if (($1 eq $owner_domain) && ($2 eq $owner_uname)) {
                    649:                             last;
                    650:                         } else {
                    651:                             push(@badroles,$firstrole);
                    652:                             $firstrole = shift(@reqroles);
                    653:                         }
                    654:                     } elsif (grep(/^\Q$firstrole\E$/,@courseroles)) {
                    655:                         last;
                    656:                     } else {
                    657:                         push(@badroles,$firstrole);
                    658:                         $firstrole = shift(@reqroles);
                    659:                     }
                    660:                 }
                    661:                 if (@badroles > 0) {
                    662:                     if (@badroles > 1) {
                    663:                         $$output .= &mt('The following requested roles are unavailable:').' '.join(', ',@badroles);
                    664:                     } else {
                    665:                         $$output .= &mt('The following requested role: [_1] is unavailable.',$badroles[0]); 
                    666:                     }
                    667:                 }
                    668:                 my $firstsec;
1.32      raeburn   669:                 unless (($firstrole eq $ccrole) || ($firstrole eq ''))  {
1.31      raeburn   670:                     $firstsec = $details->{'users'}{$userkey}{$firstrole}{'usec'}[0];
                    671:                 }
1.5       raeburn   672:                 my $userargs = {
1.29      raeburn   673:                     'auth' => $details->{'users'}{$userkey}{'authtype'},
                    674:                     'authparam' => $details->{'users'}{$userkey}{'autharg'},
                    675:                     'emailenc' => $details->{'users'}{$userkey}{'emailenc'},
1.7       raeburn   676:                     'udom' => $userdom,
1.1       raeburn   677:                     'uname' => $username,
1.29      raeburn   678:                     'pid' => $details->{'users'}{$userkey}{'studentID'},
                    679:                     'first' => $details->{'users'}{$userkey}{'firstname'},
                    680:                     'middle' => $details->{'users'}{$userkey}{'middlename'},
                    681:                     'last' => $details->{'users'}{$userkey}{'lastname'},
                    682:                     'gene' => $details->{'users'}{$userkey}{'generation'},
1.1       raeburn   683:                     'usec' => $firstsec,
1.29      raeburn   684:                     'end' => $details->{'users'}{$userkey}{'end'},
                    685:                     'start' => $details->{'users'}{$userkey}{'start'},
                    686:                     'emailaddr' => $details->{'users'}{$userkey}{'emailaddr'},
1.1       raeburn   687:                     'cid' => $courseid,
1.8       raeburn   688:                     'crs' => $crsunum,
                    689:                     'cdom' => $crsudom,
1.1       raeburn   690:                     'context' => 'createcourse',
                    691:                     'linefeed' => $linefeed,
1.38      raeburn   692:                     'role' => $details->{'users'}{$userkey}{'roles'}[0],
1.5       raeburn   693:                    };
1.38      raeburn   694:                 if ($userargs->{'role'} eq 'st') {
                    695:                     if (exists($details->{'users'}{$userkey}{'credits'})) {  
                    696:                         $userargs->{'credits'} = $details->{'users'}{$userkey}{'credits'};
                    697:                         $userargs->{'credits'} =~ s/[^\d\.]//g;
                    698:                     }
                    699:                 }
1.22      raeburn   700:                 $outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
1.1       raeburn   701: # now add other roles and other sections.
                    702:                 if ($outcome eq 'ok') {
1.32      raeburn   703:                     if ((($firstrole ne 'st') && ($firstrole ne $ccrole) && ($firstrole ne '')) && (@{$details->{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
1.29      raeburn   704:                         for (my $i=1; $i<@{$details->{'users'}{$userkey}{$firstrole}{'usec'}}; $i++) {
1.1       raeburn   705:                             my $curr_role = $firstrole;
1.29      raeburn   706:                             my $start = $details->{'users'}{$userkey}{$curr_role}{'start'};
                    707:                             my $end = $details->{'users'}{$userkey}{$curr_role}{'end'};
                    708:                             my $usec = $details->{'users'}{$userkey}{$firstrole}{'usec'}[$i];
1.1       raeburn   709:                             $url = '/'.$crsudom.'/'.$crsunum;
                    710:                             if ($usec ne '') {
                    711:                                 $url .= '/'.$usec;
                    712:                             }
1.31      raeburn   713:                             if ($firstrole =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
                    714:                                 $$output .= &Apache::loncommon::commit_customrole($userdom,$username,$url,$1,$2,$3,$start,$end,$context);
                    715:                             } else {
                    716:                                 $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
                    717:                             }
1.1       raeburn   718:                         }
                    719:                     }
1.31      raeburn   720:                     if (@reqroles > 0) {
                    721:                         foreach my $curr_role (@reqroles) {
1.29      raeburn   722:                             my $start = $details->{'users'}{$userkey}{$curr_role}{'start'};
                    723:                             my $end = $details->{'users'}{$userkey}{$curr_role}{'end'};
1.1       raeburn   724:                             if ($curr_role eq 'st') {
1.29      raeburn   725:                                 my $usec = $details->{'users'}{$userkey}{$curr_role}{'usec'}[0];
1.1       raeburn   726:                                 $url = '/'.$crsudom.'/'.$crsunum;
                    727:                                 if ($usec ne '') {
                    728:                                     $url .= '/'.$usec;
                    729:                                 }
1.38      raeburn   730:                                 my $credits;
                    731:                                 if (exists($details->{'users'}{$userkey}{'credits'})) {
                    732:                                     $credits = $details->{'users'}{$userkey}{'credits'};
                    733:                                     $credits =~ s/[^\d\.]//g;
                    734:                                 }
                    735:                                 $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context,$credits);
1.32      raeburn   736:                             } elsif ($curr_role eq $ccrole) {
1.31      raeburn   737:                                 $url = '/'.$crsudom.'/'.$crsunum;
                    738:                                 my $usec = '';
                    739:                                 $$output .=
                    740:                                     &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
                    741:                             } elsif ((grep(/^\Q$curr_role\E$/,@courseroles)) || 
                    742:                                      ($curr_role =~ m{^cr/$match_domain/$match_username/[^/]+$})) {
1.29      raeburn   743:                                 foreach my $usec (@{$details->{'users'}{$userkey}{$curr_role}{'usec'}}) {
1.1       raeburn   744:                                     $url = '/'.$crsudom.'/'.$crsunum;
                    745:                                     if ($usec ne '') {
                    746:                                         $url .= '/'.$usec;
                    747:                                     }
1.31      raeburn   748:                                     if ($curr_role =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
                    749:                                         if (($1 eq $owner_domain) && ($2 eq $owner_uname)) {
                    750:                                             $$output .= 
                    751:                                                 &Apache::loncommon::commit_customrole($userdom,$username,$url,$1,$2,$3,$start,$end,$context);
                    752:                                         } else {
                    753:                                             $$output = &mt('Requested custom role: [_1] unavailable, as it was not defined by the course owner.',$curr_role);
                    754:                                         }
                    755:                                     } else {
                    756:                                         $$output .= 
                    757:                                             &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
                    758:                                     }
1.1       raeburn   759:                                 }
1.31      raeburn   760:                             } else {
                    761:                                 $$output .= &mt('Requested role: [_1] is unavailable.',$curr_role);
1.1       raeburn   762:                             }
                    763:                         }
                    764:                     }
                    765:                 }
                    766:             } else {
1.29      raeburn   767:                 foreach my $curr_role (@{$details->{'users'}{$userkey}{'roles'}}) {
                    768:                     my $start = $details->{'users'}{$userkey}{$curr_role}{'start'};
                    769:                     my $end = $details->{'users'}{$userkey}{$curr_role}{'end'};
1.1       raeburn   770:                     if ($curr_role eq 'st') {
1.29      raeburn   771:                         my $usec = $details->{'users'}{$userkey}{$curr_role}{'usec'}[0];
1.1       raeburn   772:                         $url = '/'.$crsudom.'/'.$crsunum;
                    773:                         if ($usec ne '') {
                    774:                             $url .= '/'.$usec;
                    775:                         }
1.38      raeburn   776:                         my $credits;
                    777:                         if (exists($details->{'users'}{$userkey}{'credits'})) {
                    778:                             $credits = $details->{'users'}{$userkey}{'credits'};
                    779:                             $credits =~ s/[^\d\.]//g;
                    780:                         }
                    781:                         $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context,$credits);
1.31      raeburn   782:                     } elsif ((grep(/^\Q$curr_role\E$/,@courseroles)) ||
                    783:                                      ($curr_role =~ m{^cr/$match_domain/$match_username/[^/]+$})) {
1.29      raeburn   784:                         if (@{$details->{'users'}{$userkey}{$curr_role}{'usec'}} > 0) {
                    785:                             foreach my $usec (@{$details->{'users'}{$userkey}{$curr_role}{'usec'}}) {
1.1       raeburn   786:                                 $url = '/'.$crsudom.'/'.$crsunum;
                    787:                                 if ($usec ne '') {
                    788:                                     $url .= '/'.$usec;
                    789:                                 }
1.31      raeburn   790:                                 my $stdresult;
                    791:                                 if ($curr_role =~ m{/^cr/($match_domain)/($match_username)/([^/]+)$}) {
                    792:                                     if (($1 eq $owner_domain) && ($2 eq $owner_uname)) {
                    793:                                         $stdresult = 
                    794:                                             &Apache::loncommon::commit_customrole($userdom,$username,$url,$1,$2,$3,$start,$end,$context);
                    795:                                     } else {
                    796:                                         $stdresult = &mt('Requested custom role: [_1] unavailable, as it was not defined by the course owner.',$curr_role);
                    797:                                     }
                    798:                                 } else {
                    799:                                     $stdresult = 
                    800:                                         &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
                    801:                                 }
1.5       raeburn   802:                                 $$output .= $stdresult;
1.1       raeburn   803:                             }
                    804:                         } else {
1.5       raeburn   805:                             $url = '/'.$crsudom.'/'.$crsunum;
1.31      raeburn   806:                             if ($curr_role =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
                    807:                                 if (($1 eq $owner_domain) && ($2 eq $owner_uname)) {
                    808:                                     $$output .= 
                    809:                                         &Apache::loncommon::commit_customrole($userdom,$username,$url,$1,$2,$3,$start,$end,$context);
                    810:                                 } else {
                    811:                                     $$output .= &mt('Requested custom role: [_1] unavailable, as it was not defined by the course owner.',$curr_role);
                    812:                                 }
                    813:                             } else {
                    814:                                 $$output .= 
                    815:                                     &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,'',$context);
                    816:                             }
1.1       raeburn   817:                         }
1.31      raeburn   818:                     } else {
                    819:                         $$output .= &mt('Requested role: [_1] is unavailable.',$curr_role);
1.1       raeburn   820:                     }
                    821:                 }
                    822:             }
                    823:         }
                    824:     }
                    825: 
                    826: # Information about keys.
1.29      raeburn   827:     if ($details->{'setkeys'}) {
1.1       raeburn   828:         $$keysmsg .=
1.29      raeburn   829:  '<a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a> for '.$details->{'title'}.$linefeed;
1.1       raeburn   830:     }
                    831: # Flush the course logs so reverse user roles immediately updated
                    832:     &Apache::lonnet::flushcourselogs();
                    833:     return $courseid;
                    834: }
                    835: 
1.31      raeburn   836: sub owner_is_dc {
                    837:     my ($owner_uname,$owner_dom,$cdom) = @_;
                    838:     my $is_dc = 0;
                    839:     my %roles = &Apache::lonnet::get_my_roles($owner_uname,$owner_dom,'userroles',
                    840:                     ['active'],['dc'],[$cdom]);
                    841:     if ($roles{$owner_uname.':'.$owner_dom.':dc'}) {
                    842:         $is_dc = 1;
                    843:     }
                    844:     return $is_dc;
                    845: }
                    846: 
1.1       raeburn   847: #########################################################
                    848: #
                    849: # process_date()
                    850: # 
                    851: # input - date/time string in format YYYY:MM:DD:HH:MM:SS (:separators required).
                    852: # output - corresponding UNIX time (seconds since epoch). 
                    853: #
                    854: #########################################################
                    855: 
                    856: sub process_date {
                    857:     my $timestr = shift;
                    858:     my $timestamp = '';
1.5       raeburn   859:     if ($timestr !~ /:/) {
1.1       raeburn   860:         $timestamp = '';
                    861:     } else {
1.12      albertel  862:         my @entries = split(/:/,$timestr);
1.1       raeburn   863:         for (my $j=0; $j<@entries; $j++) {
                    864:             if ( length($entries[$j]) > 1 ) {
                    865:                 $entries[$j] =~ s/^0//;
                    866:             }
1.10      raeburn   867:             $entries[$j] =~ s/\D//g;
                    868:             if ($entries[$j] < 0) {
                    869:                 $entries[$j] = 0;
                    870:             }
1.1       raeburn   871:         }
1.5       raeburn   872:         if ($entries[1] > 0) {  
                    873:             $entries[1] = $entries[1] - 1;
                    874:         }
1.10      raeburn   875:         if ($entries[5] > 60) {
                    876:             $entries[5] = 60;
                    877:         }
                    878:         if ($entries[4] > 59) {
                    879:             $entries[4] = 59;
                    880:         }
                    881:         if ($entries[3] > 23) {
                    882:             $entries[3] = 23;
                    883:         }
                    884:         if ($entries[2] > 31) {
                    885:             $entries[2] = 31;
                    886:         }
                    887:         if ($entries[1] > 11) {
                    888:             $entries[1] = 11;
                    889:         }
                    890:         if ($entries[2] == 31) {
                    891:             if (($entries[1] == 3) || ($entries[1] == 5) ||
                    892:                 ($entries[1] == 8) || ($entries[1] == 10)) {
                    893:                 $entries[2] = 30;
                    894:             }
                    895:         }
                    896:         if ($entries[1] == 1) {
                    897:             if ($entries[2] > 29) {
                    898:                 $entries[2] = 29;
                    899:             }
                    900:             if ($entries[2] == 29) {
1.12      albertel  901:                 if ($entries[0]%4 != 0) {
1.14      raeburn   902:                     $entries[2] = 28;
1.12      albertel  903:                 } elsif ( $entries[0]%100 == 0
                    904: 			  && $entries[0]%400 != 0) {
1.14      raeburn   905: 		    $entries[2] = 28;
1.12      albertel  906: 		}
1.10      raeburn   907:             }
                    908:         }     
1.1       raeburn   909:         $timestamp =  timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
                    910:     }
                    911:     return $timestamp;
                    912: }
                    913: 
                    914: 1;

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