File:  [LON-CAPA] / loncom / misc / refresh_courseids_db.pl
Revision 1.16: download - view: text, annotated - select for diffs
Wed Jun 26 21:22:42 2013 UTC (10 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0_RC1, HEAD
- Bubblesheet grading of CODEd exams in which exam folder has either randomorder
  or randompick set causes new parameter (examcode) to be set at map level for
  a sepecific user each graded student.
- Parameter value is set to CODE on the student's bubblsheet exam.
- If used, requires course roles to be selected in a user session on a 2.11 server.
- Ensures resources are displayed in same order to student, and more importantly,
  ensures points totals will be correct in student's quickgrades view, if randompick
  was used.

    1: #!/usr/bin/perl
    2: # The LearningOnline Network
    3: #
    4: # $Id: refresh_courseids_db.pl,v 1.16 2013/06/26 21:22:42 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:                 $inst_code = '' if (!defined($inst_code));
  188:                 $owner = '' if (!defined($owner));
  189:                 if ($created eq '') {
  190:                     if (ref($currhash->{$cid}) eq 'HASH') {
  191:                         $created = $currhash->{$cid}{'created'};
  192:                         $creator = $currhash->{$cid}{'creator'};
  193:                         $creationcontext = $currhash->{$cid}{'context'};
  194:                         unless ($created eq '') {
  195:                             $changes{'internal.created'} = $created;
  196:                         }
  197:                         if ($creator =~ /^($LONCAPA::match_username):($LONCAPA::match_domain)$/) {
  198:                              $changes{'internal.creator'} = $creator;
  199:                         }
  200:                         unless ($creationcontext eq '') {
  201:                             $changes{'internal.creationcontext'} = $creationcontext;
  202:                         }
  203:                     }
  204:                     if ($created eq '') {
  205:                         if (-e "$dir/$cnum/passwd") {
  206:                             my @stats = stat("$dir/$cnum/passwd");
  207:                             $created = $stats[9];
  208:                         }
  209:                         if ($lastaccess->{$cid}) {
  210:                             if ($created eq '') {
  211:                                 $created = $lastaccess->{$cid};
  212:                             } elsif ($lastaccess->{$cid} < $created) {
  213:                                 $created = $lastaccess->{$cid};
  214:                             }
  215:                         }
  216:                         unless ($created eq '') {
  217:                             $changes{'internal.created'} = $created;
  218:                         }
  219:                     }
  220:                 }
  221:                  
  222:                 if (($chome ne '')  && ($lastaccess->{$cid} > $twodaysago)) {
  223:                     $env{'request.course.id'} = $cdom.'_'.$cnum;
  224:                     $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum;
  225:                     &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  226: 
  227:                     # check all parameters
  228:                     ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);
  229: 
  230:                     # check course type
  231:                     ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,
  232:                                                                       $reqdmajor,
  233:                                                                       $reqdminor);
  234:                     # check communication blocks 
  235:                     ($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom,
  236:                                                                      $reqdmajor,
  237:                                                                      $reqdminor);
  238:                     # check course contents
  239:                     ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,
  240:                                                                          $reqdmajor,
  241:                                                                          $reqdminor);
  242:                     delete($env{'request.course.id'});
  243:                     delete($env{'request.role'});
  244:                 } elsif ($releaserequired) {
  245:                     ($reqdmajor,$reqdminor) = split(/\./,$releaserequired);
  246:                 }
  247: 
  248:                 unless ($chome eq 'no_host') {
  249:                     if (($lastaccess->{$cid} eq '') ||
  250:                         ($lastaccess->{$cid} > $twodaysago)) {
  251:                         my $contentchange;
  252:                         if ($courseinfo{'internal.created'} eq '') {
  253:                             $contentchange = &last_map_update($cnum,$cdom);
  254:                         } else {
  255:                             unless ($courseinfo{'internal.created'} > $lastaccess->{$cid}) {
  256:                                 $contentchange = &last_map_update($cnum,$cdom);
  257:                             }
  258:                         }
  259:                         if (($contentchange) && ($contentchange > $courseinfo{'internal.contentchange'})) {
  260:                             $changes{'internal.contentchange'} = $contentchange;
  261:                         }
  262:                     }
  263:                     $courseshash->{$chome}{$cid} = {
  264:                         description => $courseinfo{'description'},
  265:                         inst_code   => $inst_code,
  266:                         owner       => $owner,
  267:                         type        => $crstype,
  268:                     };
  269:                     if ($creator ne '') {
  270:                         $courseshash->{$chome}{$cid}{'creator'} = $creator;
  271:                     }
  272:                     if ($created ne '') {
  273:                         $courseshash->{$chome}{$cid}{'created'} = $created;
  274:                     }
  275:                     if ($creationcontext ne '') {
  276:                         $courseshash->{$chome}{$cid}{'context'} = $creationcontext;
  277:                     }
  278:                     if (($inst_code ne '') && ($autoassign)) {
  279:                         unless ($gotcc) {
  280:                             %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1);
  281:                         }
  282:                         my @currcoowners;
  283:                         my @newcoowners;
  284:                         if ($courseinfo{'internal.co-owners'} ne '') {
  285:                             @currcoowners = split(',',$courseinfo{'internal.co-owners'});
  286:                         }
  287:                         foreach my $key (keys(%roleshash)) {
  288:                             if ($key =~ /^($match_username\:$match_domain)\:cc$/) {
  289:                                 my $cc = $1;
  290:                                 unless ($cc eq $owner) {
  291:                                     my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc);
  292:                                     if ($result eq 'valid') {
  293:                                         if (@newcoowners > 0) {
  294:                                             unless (grep(/^\Q$cc\E$/,@newcoowners)) { 
  295:                                                 push(@newcoowners,$cc);
  296:                                             }
  297:                                         } else {
  298:                                             push(@newcoowners,$cc);
  299:                                         }
  300:                                     }
  301:                                 }
  302:                             }
  303:                         }
  304:                         my @diffs = &Apache::loncommon::compare_arrays(\@currcoowners,\@newcoowners);
  305:                         if (@diffs > 0) {
  306:                             if (@newcoowners > 0) {
  307:                                 $changes{'internal.co-owners'} = join(',',@newcoowners);
  308:                                 $courseshash->{$chome}{$cid}{'co-owners'} = $changes{'internal.co-owners'};
  309:                             } else {
  310:                                 if ($courseinfo{'internal.co-owners'} ne '') {
  311:                                     if (&Apache::lonnet::del('environment',['internal.co-owners'],$cdom,$cnum) eq 'ok') {
  312:                                         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";
  313:                                     }
  314:                                 } else {
  315:                                     print $fh "Error occurred when updating co-ownership in course's environment.db for ".$cdom."_".$cnum."\n";
  316:                                 }
  317:                             }
  318:                         } elsif (@currcoowners > 0) {
  319:                             $courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'};
  320:                         }
  321:                     } elsif ($courseinfo{'internal.co-owners'} ne '') {
  322:                         $courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'};
  323:                     }
  324:                     foreach my $item ('categories','cloners','hidefromcat') {
  325:                         if ($courseinfo{$item} ne '') {
  326:                             $courseshash->{$chome}{$cid}{$item} = $courseinfo{$item}; 
  327:                         }
  328:                     }
  329:                     foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
  330:                         if ($courseinfo{'internal.'.$item} ne '') {
  331:                             $courseshash->{$chome}{$cid}{$item} =
  332:                                 $courseinfo{'internal.'.$item};
  333:                         }
  334:                     }
  335:                     if ($reqdmajor eq '' && $reqdminor eq '') {
  336:                         if ($courseinfo{'internal.releaserequired'} ne '') {
  337:                             $changes{'internal.releaserequired'} = '';
  338:                         }
  339:                     } else {
  340:                         my $releasereq =  $reqdmajor.'.'.$reqdminor;
  341:                         $courseshash->{$chome}{$cid}{'releaserequired'} = $releasereq;
  342:                         if ($courseinfo{'internal.releaserequired'} eq '') {
  343:                             $changes{'internal.releaserequired'} = $releasereq;
  344:                         } else {
  345:                             if ($courseinfo{'internal.releaserequired'} ne $releasereq) {
  346:                         
  347:                                 $changes{'internal.releaserequired'} = $releasereq;
  348:                             }
  349:                         }
  350:                     }
  351:                     if (keys(%changes)) {
  352:                         if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') {
  353:                             print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: ";
  354:                             foreach my $key (sort(keys(%changes))) {
  355:                                 print $fh "$key => $changes{$key} ";
  356:                             }
  357:                             print $fh "\n";
  358:                         } else {
  359:                             print $fh "Error occurred when updating course's environment.db for ".$cdom."_".$cnum."\n";
  360:                         }
  361:                     }
  362:                 }
  363:             }
  364:         }
  365:     }
  366:     return;
  367: }
  368: 
  369: sub parameter_constraints {
  370:     my ($cnum,$cdom) = @_;
  371:     my ($reqdmajor,$reqdminor);
  372:     my $resourcedata=&read_paramdata($cnum,$cdom);
  373:     if (ref($resourcedata) eq 'HASH') {
  374:         foreach my $key (keys(%{$resourcedata})) { 
  375:             foreach my $item (keys(%checkparms)) {
  376:                 if ($key =~ /(\Q$item\E)$/) {
  377:                     if (ref($checkparms{$item}) eq 'ARRAY') {
  378:                         my $value = $resourcedata->{$key};
  379:                         if ($item eq 'examcode') {
  380:                             if (&Apache::lonnet::validCODE($value)) {
  381:                                 $value = 'valid';
  382:                             } else {
  383:                                 $value = '';
  384:                             }
  385:                         }
  386:                         if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) {
  387:                             my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value});
  388:                             ($reqdmajor,$reqdminor) = 
  389:                                 &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  390:                         }
  391:                     }
  392:                 }
  393:             }
  394:         }
  395:     }
  396:     return ($reqdmajor,$reqdminor);
  397: }
  398: 
  399: sub coursetype_constraints {
  400:     my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_;
  401:     if (defined($checkcrstypes{$crstype})) {
  402:         my ($major,$minor) = split(/\./,$checkcrstypes{$crstype});
  403:         ($reqdmajor,$reqdminor) = 
  404:             &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  405:     }
  406:     return ($reqdmajor,$reqdminor);
  407: }
  408: 
  409: sub commblock_constraints {
  410:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
  411:     my %comm_blocks =  &Apache::lonnet::dump('commblock',$cdom,$cnum);
  412:     my $now = time;
  413:     if (keys(%comm_blocks) > 0) {
  414:         foreach my $block (keys(%comm_blocks)) {
  415:             if ($block =~ /^firstaccess____(.+)$/) {
  416:                 my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.timer'});
  417:                 ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  418:                 last;
  419:             } elsif ($block =~ /^(\d+)____(\d+)$/) {
  420:                 my ($start,$end) = ($1,$2);
  421:                 next if ($end < $now); 
  422:             }
  423:             if (ref($comm_blocks{$block}) eq 'HASH') {
  424:                 if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
  425:                     if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
  426:                         if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
  427:                             my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.docs'});
  428:                             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  429:                             last;
  430:                         }
  431:                     }
  432:                 }
  433:             }
  434:         }
  435:     }
  436:     return;
  437: }
  438: 
  439: sub coursecontent_constraints {
  440:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
  441:     my $navmap = Apache::lonnavmaps::navmap->new();
  442:     if (defined($navmap)) {
  443:         my %anonsubmissions =  &Apache::lonnet::dump('nohist_anonsurveys',
  444:                                                      $cdom,$cnum);
  445:         my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry',
  446:                                                      $cdom,$cnum);
  447:         my %allresponses;
  448:         my ($anonsurv_subm,$randbytry_subm);
  449:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
  450:             my %responses = $res->responseTypes();
  451:             foreach my $key (keys(%responses)) {
  452:                 next unless(exists($checkresponsetypes{$key}));
  453:                 $allresponses{$key} += $responses{$key};
  454:             }
  455:             my @parts = @{$res->parts()};
  456:             my $symb = $res->symb();
  457:             foreach my $part (@parts) {
  458:                 if (exists($anonsubmissions{$symb."\0".$part})) {
  459:                     $anonsurv_subm = 1;
  460:                 }
  461:                 if (exists($randomizetrysubm{$symb."\0".$part})) {
  462:                     $randbytry_subm = 1;
  463:                 }
  464:             }
  465:         }
  466:         foreach my $key (keys(%allresponses)) {
  467:             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
  468:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
  469:         }
  470:         if ($anonsurv_subm) {
  471:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major},
  472:                                           $anonsurvey{minor},$reqdmajor,$reqdminor);
  473:         }
  474:         if ($randbytry_subm) {
  475:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($randomizetry{major},
  476:                                           $randomizetry{minor},$reqdmajor,$reqdminor);
  477:         }
  478:     }
  479:     return ($reqdmajor,$reqdminor);
  480: }
  481: 
  482: sub update_reqd_loncaparev {
  483:     my ($major,$minor,$reqdmajor,$reqdminor) = @_;
  484:     if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) {
  485:         if ($reqdmajor eq '' || $reqdminor eq '') {
  486:             $reqdmajor = $major;
  487:             $reqdminor = $minor;
  488:         } elsif (($major > $reqdmajor) ||
  489:             ($major == $reqdmajor && $minor > $reqdminor))  {
  490:             $reqdmajor = $major;
  491:             $reqdminor = $minor;
  492:         }
  493:     }
  494:     return ($reqdmajor,$reqdminor);
  495: }
  496: 
  497: sub read_paramdata {
  498:     my ($cnum,$dom)=@_;
  499:     my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$dom);
  500:     my $classlist=&Apache::loncoursedata::get_classlist();
  501:     foreach my $student (keys(%{$classlist})) {
  502:         if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) {
  503:             my ($tuname,$tudom)=($1,$2);
  504:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
  505:             foreach my $userkey (keys(%{$useropt})) {
  506:                 if ($userkey=~/^$env{'request.course.id'}/) {
  507:                     my $newkey=$userkey;
  508:                     $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
  509:                     $$resourcedata{$newkey}=$$useropt{$userkey};
  510:                 }
  511:             }
  512:          }
  513:     }
  514:     return $resourcedata;
  515: }
  516: 
  517: sub last_map_update {
  518:     my ($cnum,$cdom) = @_;
  519:     my $lastupdate = 0;
  520:     my $path = &LONCAPA::propath($cdom,$cnum);
  521:     if (-d "$path/userfiles") {
  522:         if (opendir(my $dirh, "$path/userfiles")) {
  523:             my @maps = grep(/^default_?\d*\.(?:sequence|page)$/,readdir($dirh));
  524:             foreach my $map (@maps) {
  525:                 my $mtime = (stat("$path/userfiles/$map"))[9];
  526:                 if ($mtime > $lastupdate) {
  527:                     $lastupdate = $mtime;
  528:                 }
  529:             }
  530:         }
  531:     }
  532:     return $lastupdate;
  533: }
  534: 

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