Annotation of loncom/interface/lonrelrequtils.pm, revision 1.5

1.1       raeburn     1: #!/usr/bin/perl
                      2: # The LearningOnline Network
                      3: #
1.5     ! raeburn     4: # $Id: lonrelrequtils.pm,v 1.4 2015/09/13 21:48:05 raeburn Exp $
1.1       raeburn     5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #################################################
                     29: 
                     30: =pod
                     31: 
                     32: =head1 NAME
                     33: 
                     34: lonrelrequtils.pm
                     35: 
                     36: =head1 SYNOPSIS
                     37: 
                     38: Contains utilities used to determine the LON-CAPA version 
                     39: requirement in a course, based on course type, parameters,
                     40: responsetypes, and communication blocking events.
                     41: 
                     42: =head1 DESCRIPTION
                     43: 
                     44: lonrelrequtilities.pm includes a main subroutine:
                     45: get_release_req() which will return the current major
                     46: version and minor version requirement (if it exists).
                     47: 
                     48: =head1 SUBROUTINES
                     49: 
                     50: =over
                     51: 
                     52: =item &init_global_hashes()
                     53: 
                     54: Initializes package hashes containing version requirements for 
                     55: parameters, responsetypes, course types, anonsurvey 
                     56: parameter, and randomizetry parameter.
                     57: 
                     58: =item &get_release_req()
                     59: 
                     60: Returns current major version and minor version requirements for a course,
                     61: based on: coursetype, parameters in use, responsetypes in use in course
                     62: content, and communication blocking features in use in blocks with end dates
                     63: in the future, or in blocks triggered by activation of a timer in a timed quiz.
                     64: 
                     65: Inputs: 5
                     66: 
                     67: =over
                     68: 
                     69: =item $cnum - course "number"
                     70: 
                     71: =item $cdom - course domain
                     72: 
                     73: =item $crstype - course type: Community or Course
                     74: 
                     75: =item $readmap - boolean; if true, read course's top level map, and any
                     76:                  included maps recursively.
                     77: 
                     78: =item $globals_set - boolean: if false, call init_global_hashes
                     79: 
                     80: =back
                     81: 
                     82: 
                     83: =item &parameter_constraints()
                     84: 
                     85: Returns major version and minor version requirements for a course,
                     86: based on parameters in use in the course. (Parameters which have
1.3       raeburn    87: version requirements are listed in /home/httpd/lonTabs/releaseslist.xml).
1.1       raeburn    88: 
                     89: Inputs: 2
                     90: 
                     91: =over
                     92: 
                     93: =item $cnum - course "number"
                     94: 
                     95: =item $cdom - course domain
                     96: 
                     97: =back
                     98: 
                     99: 
                    100: =item &coursetype_constraints()
                    101: 
                    102: Returns major version and minor version requirements for a course,
                    103: taking into account course type (Community or Course).
                    104: 
                    105: Inputs: 5
                    106: 
                    107: =over
                    108: 
                    109: =item $cnum - course "number"
                    110: 
                    111: =item $cdom - course domain
                    112: 
                    113: =item $crstype - course type: Community or Course
                    114: 
                    115: =item $reqdmajor - major version requirements based on constraints 
                    116:                    considered so far (parameters).
                    117: 
                    118: =item $reqdminor - minor version requirements based on constraints 
                    119:                    considered so far (parameters).
                    120:  
                    121: =back
                    122: 
                    123: 
                    124: =item &commblock_constraints()
                    125: 
                    126: Returns major version and minor version requirements for a course,
                    127: taking into account use of communication blocking (blocks for
                    128: printouts, specified folders/resources, and/or triggering of block
                    129: by a student starting a timed quiz.
                    130: 
                    131: Inputs: 4
                    132: 
                    133: =over
                    134: 
                    135: =item $cnum - course "number"
                    136: 
                    137: =item $cdom - course domain
                    138: 
                    139: =item $reqdmajor - major version requirements based on constraints 
                    140:                    considered so far (parameters and course type).
                    141: 
                    142: =item $reqdminor - minor version requirements based on constraints
                    143:                    considered so far (parameters and course type).
                    144: 
                    145: =back
                    146: 
                    147: 
                    148: =item &coursecontent_constraints()
                    149: 
                    150: Returns major version and minor version requirements for a course,
                    151: taking into responsetypes in use in published assessment items
                    152: imported into a course.
                    153: 
                    154: Inputs: 4
                    155: 
                    156: =over
                    157: 
                    158: =item $cnum - course "number"
                    159: 
                    160: =item $cdom - course domain
                    161: 
                    162: =item $reqdmajor - major version requirements based on constraints
                    163:                    considered so far (parameters, course type, blocks).
                    164: 
                    165: =item $reqdminor - minor version requirements based on constraints
                    166:                    considered so far (parameters, course type, blocks).
                    167: 
                    168: =back
                    169: 
                    170: 
                    171: =item &update_reqd_loncaparev()
                    172: 
                    173: Returns major version and minor version requirements for a course,
                    174: taking into account new constraint type.
                    175: 
                    176: Inputs: 4
                    177: 
                    178: =over
                    179: 
                    180: =item $major - major version requirements from new constraint type
                    181: 
                    182: =item $minor - minor version requirements from new constraint type
                    183: 
                    184: =item $reqdmajor - major version requirements from constraints
                    185:                    considered so far.
                    186: 
                    187: =item $reqdminor - minor version requirements from constraints
                    188:                    considered so far.
                    189: 
                    190: =back
                    191: 
                    192: 
                    193: =item &read_paramdata()
                    194: 
                    195: Returns a reference to a hash populated with parameter settings in a
                    196: course (set both generally, and for specific students).
                    197: 
                    198: Inputs: 2
                    199: 
                    200: =over
                    201: 
                    202: =item $cnum - course "number"
                    203: 
                    204: =item $cdom - course domain
                    205: 
                    206: =back
                    207: 
                    208: 
                    209: =item &modify_course_relreq()
                    210: 
                    211: Updates course's minimum version requirement (internal.releaserequired) in 
                    212: course's environment.db, and in user's current session, and in course's
                    213: record in nohist_courseids.db on course's home server.  This can include
                    214: deleting an existing version requirement, downgrading to an earlier version,
                    215: or updating to a newer version.
                    216: 
                    217: Note: if the current server's LON-CAPA version is older than the course's
                    218: current version requirement, and a downgrade to an earlier version is being
                    219: proposed, the change will NOT be made, because of the possibility that the
                    220: current server has not checked for an attribute only available with a more 
                    221: recent version of LON-CAPA.
                    222: 
                    223: Inputs: 9
                    224: 
                    225: =over
                    226: 
                    227: =item $newmajor - (optional) major version requirements
                    228: 
                    229: =item $newminor - (optional) minor version requirements
                    230: 
                    231: =item $cnum - course "number"
                    232: 
                    233: =item $cdom - course domain
                    234: 
                    235: =item $chome - lonHostID of course's home server
                    236: 
                    237: =item $crstype - course type: Community or Course
                    238: 
                    239: =item $cid - course ID
                    240: 
                    241: =item $readmap - boolean; if true, read course's top level map, and any
                    242:                  included maps recursively.
                    243: 
                    244: =item $getrelreq - boolean; if true, call &get_release_req() to 
                    245:       return the current major version and minor version requirements.
                    246:       (needed if optional args: $newmajor and $newminor are not passed).
                    247: 
                    248: =back
                    249: 
                    250: =back
                    251: 
                    252: =cut
                    253: 
                    254: #################################################
                    255: 
                    256: package Apache::lonrelrequtils;
                    257: 
                    258: use strict;
                    259: use Apache::lonnet;
                    260: use Apache::loncommon();
                    261: use Apache::lonuserstate();
                    262: use Apache::loncoursedata();
                    263: use Apache::lonnavmaps();
                    264: use LONCAPA qw(:DEFAULT :match);
                    265: 
                    266: sub init_global_hashes {
                    267:     %Apache::lonrelrequtils::checkparms = ();
1.5     ! raeburn   268:     %Apache::lonrelrequtils::checkparmvalsmatch = ();
        !           269:     %Apache::lonrelrequtils::checkparmnamesmatch = ();
1.1       raeburn   270:     %Apache::lonrelrequtils::checkresponsetypes = ();
                    271:     %Apache::lonrelrequtils::checkcrstypes = ();
                    272:     %Apache::lonrelrequtils::anonsurvey = ();
                    273:     %Apache::lonrelrequtils::randomizetry = ();
                    274: 
                    275:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.5     ! raeburn   276:         my ($item,$name,$value,$valuematch,$namematch) = split(/:/,$key);
1.1       raeburn   277:         if ($item eq 'parameter') {
1.5     ! raeburn   278:             if ($namematch ne '') {
        !           279:                 $Apache::lonrelrequtils::checkparmnamesmatch{$namematch} = 1;
        !           280:             }
        !           281:             if ($name ne '') {
        !           282:                 if ($value ne '') {
        !           283:                     if (ref($Apache::lonrelrequtils::checkparms{$name}) eq 'ARRAY') {
        !           284:                         unless(grep(/^\Q$name\E$/,@{$Apache::lonrelrequtils::checkparms{$name}})) {
        !           285:                             push(@{$Apache::lonrelrequtils::checkparms{$name}},$value);
        !           286:                        }
        !           287:                     } else {
        !           288:                        push(@{$Apache::lonrelrequtils::checkparms{$name}},$value);
1.3       raeburn   289:                     }
1.5     ! raeburn   290:                 } elsif ($valuematch ne '') {
        !           291:                     if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$name}) eq 'ARRAY') {
        !           292:                         unless(grep(/^\Q$name\E$/,@{$Apache::lonrelrequtils::checkparmvalsmatch{$name}})) {
        !           293:                             push(@{$Apache::lonrelrequtils::checkparmvalsmatch{$name}},$valuematch);
        !           294:                        }
        !           295:                     } else {
        !           296:                         push(@{$Apache::lonrelrequtils::checkparmvalsmatch{$name}},$valuematch);
1.3       raeburn   297:                     }
                    298:                 }
1.1       raeburn   299:             }
                    300:         } elsif ($item eq 'resourcetag') {
                    301:             if ($name eq 'responsetype') {
                    302:                 $Apache::lonrelrequtils::checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
                    303:             }
                    304:         } elsif ($item eq 'course') {
                    305:             if ($name eq 'crstype') {
                    306:                 $Apache::lonrelrequtils::checkcrstypes{$value} = $Apache::lonnet::needsrelease{$key};
                    307:             }
                    308:         }
                    309:     }
                    310:     ($Apache::lonrelrequtils::anonsurvey{major},$Apache::lonrelrequtils::anonsurvey{minor}) =
1.5     ! raeburn   311:         split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'});
1.1       raeburn   312:     ($Apache::lonrelrequtils::randomizetry{major},$Apache::lonrelrequtils::randomizetry{minor}) =
1.5     ! raeburn   313:         split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'});
1.1       raeburn   314:     return;
                    315: }
                    316: 
                    317: sub get_release_req {
                    318:     my ($cnum,$cdom,$crstype,$readmap,$globals_set) = @_;
                    319:     if ($readmap) {
                    320:         &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                    321:     }
                    322:     unless ($globals_set) {
                    323:         &init_global_hashes();
                    324:     }
                    325:     # check all parameters
                    326:     my ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);
                    327: 
                    328:     # check course type
                    329:     ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,$reqdmajor,
                    330:                                                       $reqdminor);
                    331:     # check communication blocks
                    332:     ($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom,$reqdmajor,$reqdminor);
                    333: 
                    334:     # check course contents
                    335:     ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,$reqdmajor,$reqdminor);
                    336:     return ($reqdmajor,$reqdminor);
                    337: }
                    338: 
                    339: sub parameter_constraints {
                    340:     my ($cnum,$cdom) = @_;
                    341:     my ($reqdmajor,$reqdminor);
                    342:     my $resourcedata=&read_paramdata($cnum,$cdom);
1.2       raeburn   343:     my $now = time;
1.1       raeburn   344:     if (ref($resourcedata) eq 'HASH') {
                    345:         foreach my $key (keys(%{$resourcedata})) {
                    346:             foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
                    347:                 if ($key =~ /(\Q$item\E)$/) {
                    348:                     if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
                    349:                         my $value = $resourcedata->{$key};
                    350:                         if ($item eq 'examcode') {
                    351:                             if (&Apache::lonnet::validCODE($value)) {
                    352:                                 $value = 'valid';
                    353:                             } else {
                    354:                                 $value = '';
                    355:                             }
1.2       raeburn   356:                         } elsif ($item eq 'printstartdate') {
                    357:                             if ($value =~ /^\d+$/) {
                    358:                                 if ($value > $now) {
                    359:                                     $value = 'future';
                    360:                                 }
                    361:                             }
                    362:                         } elsif ($item eq 'printenddate') {
                    363:                             if ($value =~ /^\d+$/) {
                    364:                                 if ($value < $now) {
                    365:                                     $value = 'past';
                    366:                                 }
                    367:                             }
1.1       raeburn   368:                         }
                    369:                         if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
1.3       raeburn   370:                             my ($major,$minor) = 
1.5     ! raeburn   371:                                 split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'});
1.1       raeburn   372:                             ($reqdmajor,$reqdminor) =
                    373:                                 &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    374:                         }
                    375:                     }
                    376:                 }
                    377:             }
1.5     ! raeburn   378:             foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) { 
1.3       raeburn   379:                 if ($key =~ /(\Q$item\E)$/) {
1.5     ! raeburn   380:                     if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.3       raeburn   381:                         my $value = $resourcedata->{$key};
1.5     ! raeburn   382:                         foreach my $entry (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.3       raeburn   383:                             my $regexp;
                    384:                             if (($item eq 'lenient') && ($entry eq 'weighted')) {
                    385:                                 $regexp = '^[\-\.\d]+,[\-\.\d]+,[\-\.\d]+,[\-\.\d]+$';      
                    386:                             } elsif (($item eq 'acc') && ($entry eq '_denyfrom_')) {
                    387:                                 $regexp = '\!';
1.4       raeburn   388:                             } elsif (($item eq 'interval') && ($entry eq 'done')) {
                    389:                                 $regexp = '^\d+_done$';
1.3       raeburn   390:                             }
                    391:                             if ($regexp ne '') {
                    392:                                 if ($value =~ /$regexp/) {
                    393:                                     my ($major,$minor) =
1.5     ! raeburn   394:                                         split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$entry.':'});
1.3       raeburn   395:                                     ($reqdmajor,$reqdminor) =
                    396:                                         &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    397:                                     last;
                    398:                                 }
                    399:                             }
                    400:                         }
                    401:                     }
                    402:                 }
                    403:             }
1.5     ! raeburn   404:             foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
        !           405:                 my $regexp;
        !           406:                 if ($item eq 'maplevelrecurse') {
        !           407:                     $regexp = '\.(?:sequence|page)___\(rec\)\.';
        !           408:                 }
        !           409:                 if ($regexp ne '') {
        !           410:                     if ($key =~ /$regexp/) {
        !           411:                         my ($major,$minor) =
        !           412:                           split(/\./,$Apache::lonnet::needsrelease{'parameter::::'.$item});
        !           413:                           ($reqdmajor,$reqdminor) =
        !           414:                               &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
        !           415: 
        !           416:                     }
        !           417:                 }
        !           418:             }
1.1       raeburn   419:         }
                    420:     }
                    421:     return ($reqdmajor,$reqdminor);
                    422: }
                    423: 
                    424: sub coursetype_constraints {
                    425:     my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_;
                    426:     if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
                    427:         my ($major,$minor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
                    428:         ($reqdmajor,$reqdminor) =
                    429:             &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    430:     }
                    431:     return ($reqdmajor,$reqdminor);
                    432: }
                    433: 
                    434: sub commblock_constraints {
                    435:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
                    436:     my %comm_blocks =  &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                    437:     my $now = time;
                    438:     if (keys(%comm_blocks) > 0) {
                    439:         foreach my $block (keys(%comm_blocks)) {
                    440:             if ($block =~ /^firstaccess____(.+)$/) {
1.5     ! raeburn   441:                 my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course:commblock:timer'});
1.1       raeburn   442:                 ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    443:                 last;
                    444:             } elsif ($block =~ /^(\d+)____(\d+)$/) {
                    445:                 my ($start,$end) = ($1,$2);
                    446:                 next if ($end < $now);
                    447:             }
                    448:             if (ref($comm_blocks{$block}) eq 'HASH') {
                    449:                 if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
                    450:                     if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
                    451:                         if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.5     ! raeburn   452:                             my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course:commblock:docs'});
1.1       raeburn   453:                             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    454:                             last;
                    455:                         }
                    456:                     }
                    457:                     if ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.5     ! raeburn   458:                         my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course:commblock:printout'});
1.1       raeburn   459:                         ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    460:                         last;
                    461:                     }
                    462:                 }
                    463:             }
                    464:         }
                    465:     }
                    466:     return ($reqdmajor,$reqdminor);
                    467: }
                    468: 
                    469: sub coursecontent_constraints {
                    470:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
                    471:     my $navmap = Apache::lonnavmaps::navmap->new();
                    472:     if (defined($navmap)) {
                    473:         my %anonsubmissions =  &Apache::lonnet::dump('nohist_anonsurveys',
                    474:                                                      $cdom,$cnum);
                    475:         my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry',
                    476:                                                      $cdom,$cnum);
                    477:         my %allresponses;
                    478:         my ($anonsurv_subm,$randbytry_subm);
                    479:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
                    480:             my %responses = $res->responseTypes();
                    481:             foreach my $key (keys(%responses)) {
                    482:                 next unless(exists($Apache::lonrelrequtils::checkresponsetypes{$key}));
                    483:                 $allresponses{$key} += $responses{$key};
                    484:             }
                    485:             my @parts = @{$res->parts()};
                    486:             my $symb = $res->symb();
                    487:             foreach my $part (@parts) {
                    488:                 if (exists($anonsubmissions{$symb."\0".$part})) {
                    489:                     $anonsurv_subm = 1;
                    490:                 }
                    491:                 if (exists($randomizetrysubm{$symb."\0".$part})) {
                    492:                     $randbytry_subm = 1;
                    493:                 }
                    494:             }
                    495:         }
                    496:         foreach my $key (keys(%allresponses)) {
                    497:             my ($major,$minor) = split(/\./,$Apache::lonrelrequtils::checkresponsetypes{$key});
                    498:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    499:         }
                    500:         if ($anonsurv_subm) {
                    501:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($Apache::lonrelrequtils::anonsurvey{major},
                    502:                                           $Apache::lonrelrequtils::anonsurvey{minor},$reqdmajor,$reqdminor);
                    503:         }
                    504:         if ($randbytry_subm) {
                    505:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($Apache::lonrelrequtils::randomizetry{major},
                    506:                                           $Apache::lonrelrequtils::randomizetry{minor},$reqdmajor,$reqdminor);
                    507:         }
                    508:     }
                    509:     return ($reqdmajor,$reqdminor);
                    510: }
                    511: 
                    512: sub update_reqd_loncaparev {
                    513:     my ($major,$minor,$reqdmajor,$reqdminor) = @_;
                    514:     if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) {
                    515:         if ($reqdmajor eq '' || $reqdminor eq '') {
                    516:             $reqdmajor = $major;
                    517:             $reqdminor = $minor;
                    518:         } elsif (($major > $reqdmajor) ||
                    519:             ($major == $reqdmajor && $minor > $reqdminor))  {
                    520:             $reqdmajor = $major;
                    521:             $reqdminor = $minor;
                    522:         }
                    523:     }
                    524:     return ($reqdmajor,$reqdminor);
                    525: }
                    526: 
                    527: sub read_paramdata {
                    528:     my ($cnum,$cdom)=@_;
                    529:     my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$cdom);
                    530:     my $classlist=&Apache::loncoursedata::get_classlist();
                    531:     foreach my $student (keys(%{$classlist})) {
                    532:         if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) {
                    533:             my ($tuname,$tudom)=($1,$2);
                    534:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
                    535:             foreach my $userkey (keys(%{$useropt})) {
                    536:                 if ($userkey=~/^\Q$cdom\E_\Q$cnum\E/) {
                    537:                     my $newkey=$userkey;
                    538:                     $newkey=~s/^(\Q$cdom\E_\Q$cnum\E\.)/$1\[useropt\:$tuname\:$tudom\]\./;
                    539:                     $$resourcedata{$newkey}=$$useropt{$userkey};
                    540:                 }
                    541:             }
                    542:         }
                    543:     }
                    544:     return $resourcedata;
                    545: }
                    546: 
                    547: sub modify_course_relreq {
                    548:     my ($newmajor,$newminor,$cnum,$cdom,$chome,$crstype,$cid,$readmap,$getrelreq) = @_;
                    549:     if ($cnum eq '' || $cdom eq '' || $chome eq '' || $crstype eq '' || $cid eq '') {
                    550:         $cid = $env{'request.course.id'};
                    551:         $cdom = $env{'course.'.$cid.'.domain'};
                    552:         $cnum = $env{'course.'.$cid.'.num'};
                    553:         $chome = $env{'course.'.$cid.'.home'};
                    554:         $crstype = $env{'course.'.$cid.'.type'};
                    555:         if ($crstype eq '') {
                    556:             $crstype = 'Course';
                    557:         }
                    558:     }
                    559:     if ($getrelreq) {
                    560:         ($newmajor,$newminor) = &get_release_req($cnum,$cdom,$crstype,$readmap);
                    561:     }
                    562:     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                    563:     my $needsupdate;
                    564:     if ($curr_reqd_hash{'internal.releaserequired'} eq '') {
                    565:         if (($newmajor ne '') && ($newminor ne '')) { 
                    566:             $needsupdate = 1;
                    567:         }
                    568:     } else {
                    569:         my ($currmajor,$currminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
                    570:         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
                    571:         my $serverdom = $Apache::lonnet::perlvar{'lonDefDomain'};
                    572:         my $serverrev = &Apache::lonnet::get_server_loncaparev($serverdom,$lonhost);
                    573:         my ($servermajor,$serverminor) = split(/\./,$serverrev);     
                    574:         unless (($currmajor > $servermajor) || (($currmajor == $servermajor) && ($currminor > $serverminor))) {
                    575:             if (($currmajor != $newmajor) || ($currminor != $newminor)) {
                    576:                 $needsupdate = 1;
                    577:             }
                    578:         }
                    579:     }
                    580:     if ($needsupdate) {
                    581:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
                    582:         my $result;
                    583:         if (($newmajor eq '') && ($newminor eq '')) {
                    584:             $result = &Apache::lonnet::del('environment',['internal.releaserequired'],$cdom,$cnum);
                    585:             if ($result eq 'ok') {
                    586:                 &Apache::lonnet::delenv('course.'.$cid.'.internal.releaserequired');
                    587:                 $crsinfo{$cid}{'releaserequired'} = '';
                    588:             }
                    589:         } else {
                    590:             my %needshash = (
                    591:                               'internal.releaserequired' => $newmajor.'.'.$newminor,
                    592:                             );
                    593:             $result = &Apache::lonnet::put('environment',\%needshash,$cdom,$cnum);
                    594:             if ($result eq 'ok') {
                    595:                 &Apache::lonnet::appenv({'course.'.$cid.'.internal.releaserequired' => $newmajor.'.'.$newminor});
                    596:                 if (ref($crsinfo{$cid}) eq 'HASH') {
                    597:                     $crsinfo{$cid}{'releaserequired'} = $newmajor.'.'.$newminor
                    598:                 }
                    599:             }
                    600:         }
                    601:         if ($result eq 'ok') {
                    602:             &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
                    603:         }
                    604:     }
                    605:     return;
                    606: }
                    607: 
                    608: 1;

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