File:  [LON-CAPA] / loncom / misc / refresh_courseids_db.pl
Revision 1.17: download - view: text, annotated - select for diffs
Wed Dec 25 20:43:51 2013 UTC (10 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0_RC3, version_2_11_0_RC2, HEAD
- Domain configuration used to set generation of unique six character code
  as course identifier when processing course requests, can be set
  separately for different request types - official, unofficial, community
  or textbook.
- Where a unique code is set for a course store in nohist_courseids.db on
  domain's library server(s).

    1: #!/usr/bin/perl
    2: # The LearningOnline Network
    3: #
    4: # $Id: refresh_courseids_db.pl,v 1.17 2013/12/25 20:43:51 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: =pod
   31: 
   32: =head1 NAME
   33: 
   34: refresh_courseids_db.pl
   35: 
   36: =head1 SYNOPSIS
   37: 
   38: refresh_courseids_db.pl is run on a library server and gathers 
   39: course information for each course for which the current server is
   40: the home server.  Entries (excluding last access time) for each course 
   41: in nohist_courseids.db are updated.   
   42: 
   43: =head1 DESCRIPTION
   44: 
   45: refresh_courseids_db.pl will update course information, apart 
   46: from last access time, in nohist_courseids.db, using course data   
   47: from each course's environment.db file.
   48: 
   49: =cut
   50: 
   51: #################################################
   52: 
   53: use strict;
   54: use lib '/home/httpd/lib/perl/';
   55: use Apache::lonnet;
   56: use Apache::loncommon;
   57: use Apache::lonuserstate;
   58: use Apache::loncoursedata;
   59: use Apache::lonnavmaps;
   60: use LONCAPA qw(:DEFAULT :match);
   61: 
   62: exit if ($Apache::lonnet::perlvar{'lonRole'} ne 'library');
   63: 
   64: use vars qw( %checkparms %checkresponsetypes %checkcrstypes %anonsurvey %randomizetry );
   65: 
   66: #  Make sure this process is running from user=www
   67: my $wwwid=getpwnam('www');
   68: if ($wwwid!=$<) {
   69:     my $emailto="$Apache::lonnet::perlvar{'lonAdmEMail'},$Apache::lonnet::perlvar{'lonSysEMail'}";
   70:     my $subj="LON: $Apache::lonnet::perlvar{'lonHostID'} User ID mismatch";
   71:     system("echo 'User ID mismatch. refresh_courseids_db.pl must be run as user www.' |\
   72:  mail -s '$subj' $emailto > /dev/null");
   73:     exit 1;
   74: }
   75: #
   76: # Let people know we are running
   77: open(my $fh,'>>'.$Apache::lonnet::perlvar{'lonDaemons'}.'/logs/refreshcourseids_db.log');
   78: print $fh "==== refresh_courseids_db.pl Run ".localtime()."====\n";
   79: 
   80: my @domains = sort(&Apache::lonnet::current_machine_domains());
   81: my @ids=&Apache::lonnet::current_machine_ids();
   82: 
   83: &Apache::loncommon::build_release_hashes(\%checkparms,\%checkresponsetypes,
   84:                                          \%checkcrstypes,\%anonsurvey,\%randomizetry);
   85: $env{'allowed.bre'} = 'F';
   86: 
   87: foreach my $dom (@domains) {
   88:     $env{'user.domain'} = $dom;
   89:     $env{'user.name'} = &Apache::lonnet::get_domainconfiguser($dom);
   90:     my %courseshash;
   91:     my %currhash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@ids,'.');
   92:     my %lastaccess = &Apache::lonnet::courselastaccess($dom,undef,\@ids);
   93:     my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom;
   94:     my %domdesign = &Apache::loncommon::get_domainconf($dom);
   95:     my $autoassign = $domdesign{$dom.'.autoassign.co-owners'};
   96:     &recurse_courses($dom,$dir,0,\%courseshash,\%currhash,\%lastaccess,$autoassign,$fh);
   97:     foreach my $lonhost (keys(%courseshash)) {
   98:         if (ref($courseshash{$lonhost}) eq 'HASH') {
   99:             if (&Apache::lonnet::courseidput($dom,$courseshash{$lonhost},$lonhost,'notime') eq 'ok') {
  100:                 print $fh "nohist_courseids.db updated successfully for domain $dom on lonHostID $lonhost\n";
  101:             } else {
  102:                 print $fh "Error occurred when updating nohist_courseids.db for domain $dom on lonHostID $lonhost\n";
  103:             }
  104:         }
  105:     }
  106:     delete($env{'user.name'});
  107:     delete($env{'user.domain'});
  108: }
  109: 
  110: delete($env{'allowed.bre'});
  111: 
  112: ## Finished!
  113: print $fh "==== refresh_courseids.db completed ".localtime()." ====\n";
  114: close($fh);
  115: 
  116: sub recurse_courses {
  117:     my ($cdom,$dir,$depth,$courseshash,$currhash,$lastaccess,$autoassign,$fh) = @_;
  118:     next unless (ref($currhash) eq 'HASH');
  119:     if (-d $dir) {
  120:         opendir(DIR,$dir);
  121:         my @contents = grep(!/^\./,readdir(DIR));
  122:         closedir(DIR);
  123:         $depth ++;
  124:         foreach my $item (@contents) {
  125:             if ($depth < 4) {
  126:                 &recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash,
  127:                                  $currhash,$lastaccess,$autoassign,$fh);
  128:             } elsif ($item =~ /^$match_courseid$/) {
  129:                 my $cnum = $item;
  130:                 my $cid = $cdom.'_'.$cnum;
  131:                 unless (ref($currhash->{$cid}) eq 'HASH') {
  132:                     my $is_course = 0;
  133:                     if (-e "$dir/$cnum/passwd") {
  134:                         if (open(my $pwfh,"<$dir/$cnum/passwd")) {
  135:                             while (<$pwfh>) {
  136:                                 if (/^none:/) {
  137:                                     $is_course = 1;
  138:                                     last;
  139:                                 }
  140:                             } 
  141:                         }
  142:                     }
  143:                     next unless ($is_course);
  144:                     my @stats = stat("$dir/$cnum/passwd");
  145:                     print $fh "Course missing from nohist_courseids.db: $cid, created:".localtime($stats[9])."\n";
  146:                 }
  147:                 my %courseinfo=&Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
  148:                 my %changes = ();
  149:                 my $crstype = $courseinfo{'type'};
  150:                 if ($crstype eq '') {
  151:                     if ($cnum =~ /^$match_community$/) {
  152:                         $crstype = 'Community';
  153:                     } else {
  154:                         $crstype = 'Course';
  155:                     }
  156:                     $changes{'type'} = $crstype;
  157:                 }
  158:                 my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
  159:                 my $owner = $courseinfo{'internal.courseowner'};
  160:                 my $twodaysago = time - 172800;
  161:                 my (%roleshash,$gotcc,$reqdmajor,$reqdminor);
  162:                 if ($owner eq '') {
  163:                     %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1);
  164:                     $gotcc = 1;
  165:                     if (keys(%roleshash) == 1) {
  166:                         foreach my $key (keys(%roleshash)) {
  167:                             if ($key =~ /^($match_username\:$match_domain)\:cc$/) {
  168:                                 $owner = $1;
  169:                                 $changes{'internal.courseowner'} = $owner;
  170:                             }
  171:                         }
  172:                     }
  173:                 } elsif ($owner !~ /:/) {
  174:                     if ($owner =~ /^$match_username$/) {
  175:                         my $ownerhome=&Apache::lonnet::homeserver($owner,$cdom);
  176:                         unless (($ownerhome eq '') || ($ownerhome eq 'no_host')) {
  177:                             $owner .= ':'.$cdom;
  178:                             $changes{'internal.courseowner'} = $owner;
  179:                         }
  180:                     }
  181:                 }
  182:                 my $created = $courseinfo{'internal.created'};
  183:                 my $creator = $courseinfo{'internal.creator'};
  184:                 my $creationcontext = $courseinfo{'internal.creationcontext'};
  185:                 my $inst_code = $courseinfo{'internal.coursecode'};
  186:                 my $releaserequired = $courseinfo{'internal.releaserequired'};
  187:                 my $uniquecode = $courseinfo{'internal.uniquecode'};
  188:                 $inst_code = '' if (!defined($inst_code));
  189:                 $owner = '' if (!defined($owner));
  190:                 $uniquecode = '' if (!defined($uniquecode));
  191:                 if ($created eq '') {
  192:                     if (ref($currhash->{$cid}) eq 'HASH') {
  193:                         $created = $currhash->{$cid}{'created'};
  194:                         $creator = $currhash->{$cid}{'creator'};
  195:                         $creationcontext = $currhash->{$cid}{'context'};
  196:                         unless ($created eq '') {
  197:                             $changes{'internal.created'} = $created;
  198:                         }
  199:                         if ($creator =~ /^($LONCAPA::match_username):($LONCAPA::match_domain)$/) {
  200:                              $changes{'internal.creator'} = $creator;
  201:                         }
  202:                         unless ($creationcontext eq '') {
  203:                             $changes{'internal.creationcontext'} = $creationcontext;
  204:                         }
  205:                     }
  206:                     if ($created eq '') {
  207:                         if (-e "$dir/$cnum/passwd") {
  208:                             my @stats = stat("$dir/$cnum/passwd");
  209:                             $created = $stats[9];
  210:                         }
  211:                         if ($lastaccess->{$cid}) {
  212:                             if ($created eq '') {
  213:                                 $created = $lastaccess->{$cid};
  214:                             } elsif ($lastaccess->{$cid} < $created) {
  215:                                 $created = $lastaccess->{$cid};
  216:                             }
  217:                         }
  218:                         unless ($created eq '') {
  219:                             $changes{'internal.created'} = $created;
  220:                         }
  221:                     }
  222:                 }
  223:                  
  224:                 if (($chome ne '')  && ($lastaccess->{$cid} > $twodaysago)) {
  225:                     $env{'request.course.id'} = $cdom.'_'.$cnum;
  226:                     $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum;
  227:                     &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  228: 
  229:                     # check all parameters
  230:                     ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);
  231: 
  232:                     # check course type
  233:                     ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,
  234:                                                                       $reqdmajor,
  235:                                                                       $reqdminor);
  236:                     # check communication blocks 
  237:                     ($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom,
  238:                                                                      $reqdmajor,
  239:                                                                      $reqdminor);
  240:                     # check course contents
  241:                     ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,
  242:                                                                          $reqdmajor,
  243:                                                                          $reqdminor);
  244:                     delete($env{'request.course.id'});
  245:                     delete($env{'request.role'});
  246:                 } elsif ($releaserequired) {
  247:                     ($reqdmajor,$reqdminor) = split(/\./,$releaserequired);
  248:                 }
  249: 
  250:                 unless ($chome eq 'no_host') {
  251:                     if (($lastaccess->{$cid} eq '') ||
  252:                         ($lastaccess->{$cid} > $twodaysago)) {
  253:                         my $contentchange;
  254:                         if ($courseinfo{'internal.created'} eq '') {
  255:                             $contentchange = &last_map_update($cnum,$cdom);
  256:                         } else {
  257:                             unless ($courseinfo{'internal.created'} > $lastaccess->{$cid}) {
  258:                                 $contentchange = &last_map_update($cnum,$cdom);
  259:                             }
  260:                         }
  261:                         if (($contentchange) && ($contentchange > $courseinfo{'internal.contentchange'})) {
  262:                             $changes{'internal.contentchange'} = $contentchange;
  263:                         }
  264:                     }
  265:                     $courseshash->{$chome}{$cid} = {
  266:                         description => $courseinfo{'description'},
  267:                         inst_code   => $inst_code,
  268:                         owner       => $owner,
  269:                         type        => $crstype,
  270:                     };
  271:                     if ($creator ne '') {
  272:                         $courseshash->{$chome}{$cid}{'creator'} = $creator;
  273:                     }
  274:                     if ($created ne '') {
  275:                         $courseshash->{$chome}{$cid}{'created'} = $created;
  276:                     }
  277:                     if ($creationcontext ne '') {
  278:                         $courseshash->{$chome}{$cid}{'context'} = $creationcontext;
  279:                     }
  280:                     if (($inst_code ne '') && ($autoassign)) {
  281:                         unless ($gotcc) {
  282:                             %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1);
  283:                         }
  284:                         my @currcoowners;
  285:                         my @newcoowners;
  286:                         if ($courseinfo{'internal.co-owners'} ne '') {
  287:                             @currcoowners = split(',',$courseinfo{'internal.co-owners'});
  288:                         }
  289:                         foreach my $key (keys(%roleshash)) {
  290:                             if ($key =~ /^($match_username\:$match_domain)\:cc$/) {
  291:                                 my $cc = $1;
  292:                                 unless ($cc eq $owner) {
  293:                                     my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc);
  294:                                     if ($result eq 'valid') {
  295:                                         if (@newcoowners > 0) {
  296:                                             unless (grep(/^\Q$cc\E$/,@newcoowners)) { 
  297:                                                 push(@newcoowners,$cc);
  298:                                             }
  299:                                         } else {
  300:                                             push(@newcoowners,$cc);
  301:                                         }
  302:                                     }
  303:                                 }
  304:                             }
  305:                         }
  306:                         my @diffs = &Apache::loncommon::compare_arrays(\@currcoowners,\@newcoowners);
  307:                         if (@diffs > 0) {
  308:                             if (@newcoowners > 0) {
  309:                                 $changes{'internal.co-owners'} = join(',',@newcoowners);
  310:                                 $courseshash->{$chome}{$cid}{'co-owners'} = $changes{'internal.co-owners'};
  311:                             } else {
  312:                                 if ($courseinfo{'internal.co-owners'} ne '') {
  313:                                     if (&Apache::lonnet::del('environment',['internal.co-owners'],$cdom,$cnum) eq 'ok') {
  314:                                         print $fh "Former co-owner(s): $courseinfo{'internal.co-owners'} for official course: $inst_code (".$cdom."_".$cnum.") no longer active CCs, co-ownership status deleted.\n";
  315:                                     }
  316:                                 } else {
  317:                                     print $fh "Error occurred when updating co-ownership in course's environment.db for ".$cdom."_".$cnum."\n";
  318:                                 }
  319:                             }
  320:                         } elsif (@currcoowners > 0) {
  321:                             $courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'};
  322:                         }
  323:                     } elsif ($courseinfo{'internal.co-owners'} ne '') {
  324:                         $courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'};
  325:                     }
  326:                     foreach my $item ('categories','cloners','hidefromcat') {
  327:                         if ($courseinfo{$item} ne '') {
  328:                             $courseshash->{$chome}{$cid}{$item} = $courseinfo{$item}; 
  329:                         }
  330:                     }
  331:                     foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date','uniquecode') {
  332:                         if ($courseinfo{'internal.'.$item} ne '') {
  333:                             $courseshash->{$chome}{$cid}{$item} =
  334:                                 $courseinfo{'internal.'.$item};
  335:                         }
  336:                     }
  337:                     if ($reqdmajor eq '' && $reqdminor eq '') {
  338:                         if ($courseinfo{'internal.releaserequired'} ne '') {
  339:                             $changes{'internal.releaserequired'} = '';
  340:                         }
  341:                     } else {
  342:                         my $releasereq =  $reqdmajor.'.'.$reqdminor;
  343:                         $courseshash->{$chome}{$cid}{'releaserequired'} = $releasereq;
  344:                         if ($courseinfo{'internal.releaserequired'} eq '') {
  345:                             $changes{'internal.releaserequired'} = $releasereq;
  346:                         } else {
  347:                             if ($courseinfo{'internal.releaserequired'} ne $releasereq) {
  348:                         
  349:                                 $changes{'internal.releaserequired'} = $releasereq;
  350:                             }
  351:                         }
  352:                     }
  353:                     if (keys(%changes)) {
  354:                         if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') {
  355:                             print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: ";
  356:                             foreach my $key (sort(keys(%changes))) {
  357:                                 print $fh "$key => $changes{$key} ";
  358:                             }
  359:                             print $fh "\n";
  360:                         } else {
  361:                             print $fh "Error occurred when updating course's environment.db for ".$cdom."_".$cnum."\n";
  362:                         }
  363:                     }
  364:                 }
  365:             }
  366:         }
  367:     }
  368:     return;
  369: }
  370: 
  371: sub parameter_constraints {
  372:     my ($cnum,$cdom) = @_;
  373:     my ($reqdmajor,$reqdminor);
  374:     my $resourcedata=&read_paramdata($cnum,$cdom);
  375:     if (ref($resourcedata) eq 'HASH') {
  376:         foreach my $key (keys(%{$resourcedata})) { 
  377:             foreach my $item (keys(%checkparms)) {
  378:                 if ($key =~ /(\Q$item\E)$/) {
  379:                     if (ref($checkparms{$item}) eq 'ARRAY') {
  380:                         my $value = $resourcedata->{$key};
  381:                         if ($item eq 'examcode') {
  382:                             if (&Apache::lonnet::validCODE($value)) {
  383:                                 $value = 'valid';
  384:                             } else {
  385:                                 $value = '';
  386:                             }
  387:                         }
  388:                         if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) {
  389:                             my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value});
  390:                             ($reqdmajor,$reqdminor) = 
  391:                                 &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  392:                         }
  393:                     }
  394:                 }
  395:             }
  396:         }
  397:     }
  398:     return ($reqdmajor,$reqdminor);
  399: }
  400: 
  401: sub coursetype_constraints {
  402:     my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_;
  403:     if (defined($checkcrstypes{$crstype})) {
  404:         my ($major,$minor) = split(/\./,$checkcrstypes{$crstype});
  405:         ($reqdmajor,$reqdminor) = 
  406:             &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  407:     }
  408:     return ($reqdmajor,$reqdminor);
  409: }
  410: 
  411: sub commblock_constraints {
  412:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
  413:     my %comm_blocks =  &Apache::lonnet::dump('commblock',$cdom,$cnum);
  414:     my $now = time;
  415:     if (keys(%comm_blocks) > 0) {
  416:         foreach my $block (keys(%comm_blocks)) {
  417:             if ($block =~ /^firstaccess____(.+)$/) {
  418:                 my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.timer'});
  419:                 ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  420:                 last;
  421:             } elsif ($block =~ /^(\d+)____(\d+)$/) {
  422:                 my ($start,$end) = ($1,$2);
  423:                 next if ($end < $now); 
  424:             }
  425:             if (ref($comm_blocks{$block}) eq 'HASH') {
  426:                 if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
  427:                     if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
  428:                         if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
  429:                             my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.docs'});
  430:                             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  431:                             last;
  432:                         }
  433:                     }
  434:                 }
  435:             }
  436:         }
  437:     }
  438:     return;
  439: }
  440: 
  441: sub coursecontent_constraints {
  442:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
  443:     my $navmap = Apache::lonnavmaps::navmap->new();
  444:     if (defined($navmap)) {
  445:         my %anonsubmissions =  &Apache::lonnet::dump('nohist_anonsurveys',
  446:                                                      $cdom,$cnum);
  447:         my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry',
  448:                                                      $cdom,$cnum);
  449:         my %allresponses;
  450:         my ($anonsurv_subm,$randbytry_subm);
  451:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
  452:             my %responses = $res->responseTypes();
  453:             foreach my $key (keys(%responses)) {
  454:                 next unless(exists($checkresponsetypes{$key}));
  455:                 $allresponses{$key} += $responses{$key};
  456:             }
  457:             my @parts = @{$res->parts()};
  458:             my $symb = $res->symb();
  459:             foreach my $part (@parts) {
  460:                 if (exists($anonsubmissions{$symb."\0".$part})) {
  461:                     $anonsurv_subm = 1;
  462:                 }
  463:                 if (exists($randomizetrysubm{$symb."\0".$part})) {
  464:                     $randbytry_subm = 1;
  465:                 }
  466:             }
  467:         }
  468:         foreach my $key (keys(%allresponses)) {
  469:             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
  470:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  471:         }
  472:         if ($anonsurv_subm) {
  473:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major},
  474:                                           $anonsurvey{minor},$reqdmajor,$reqdminor);
  475:         }
  476:         if ($randbytry_subm) {
  477:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($randomizetry{major},
  478:                                           $randomizetry{minor},$reqdmajor,$reqdminor);
  479:         }
  480:     }
  481:     return ($reqdmajor,$reqdminor);
  482: }
  483: 
  484: sub update_reqd_loncaparev {
  485:     my ($major,$minor,$reqdmajor,$reqdminor) = @_;
  486:     if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) {
  487:         if ($reqdmajor eq '' || $reqdminor eq '') {
  488:             $reqdmajor = $major;
  489:             $reqdminor = $minor;
  490:         } elsif (($major > $reqdmajor) ||
  491:             ($major == $reqdmajor && $minor > $reqdminor))  {
  492:             $reqdmajor = $major;
  493:             $reqdminor = $minor;
  494:         }
  495:     }
  496:     return ($reqdmajor,$reqdminor);
  497: }
  498: 
  499: sub read_paramdata {
  500:     my ($cnum,$dom)=@_;
  501:     my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$dom);
  502:     my $classlist=&Apache::loncoursedata::get_classlist();
  503:     foreach my $student (keys(%{$classlist})) {
  504:         if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) {
  505:             my ($tuname,$tudom)=($1,$2);
  506:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
  507:             foreach my $userkey (keys(%{$useropt})) {
  508:                 if ($userkey=~/^$env{'request.course.id'}/) {
  509:                     my $newkey=$userkey;
  510:                     $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
  511:                     $$resourcedata{$newkey}=$$useropt{$userkey};
  512:                 }
  513:             }
  514:          }
  515:     }
  516:     return $resourcedata;
  517: }
  518: 
  519: sub last_map_update {
  520:     my ($cnum,$cdom) = @_;
  521:     my $lastupdate = 0;
  522:     my $path = &LONCAPA::propath($cdom,$cnum);
  523:     if (-d "$path/userfiles") {
  524:         if (opendir(my $dirh, "$path/userfiles")) {
  525:             my @maps = grep(/^default_?\d*\.(?:sequence|page)$/,readdir($dirh));
  526:             foreach my $map (@maps) {
  527:                 my $mtime = (stat("$path/userfiles/$map"))[9];
  528:                 if ($mtime > $lastupdate) {
  529:                     $lastupdate = $mtime;
  530:                 }
  531:             }
  532:         }
  533:     }
  534:     return $lastupdate;
  535: }
  536: 

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