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

1.1       raeburn     1: #!/usr/bin/perl
                      2: # The LearningOnline Network
                      3: #
1.3     ! raeburn     4: # $Id: lonrelrequtils.pm,v 1.2 2014/06/13 01:48:26 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.3     ! raeburn   268:     %Apache::lonrelrequtils::checkparmsmatch = ();
1.1       raeburn   269:     %Apache::lonrelrequtils::checkresponsetypes = ();
                    270:     %Apache::lonrelrequtils::checkcrstypes = ();
                    271:     %Apache::lonrelrequtils::anonsurvey = ();
                    272:     %Apache::lonrelrequtils::randomizetry = ();
                    273: 
                    274:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.3     ! raeburn   275:         my ($item,$name,$value,$valuematch) = split(/:/,$key);
1.1       raeburn   276:         if ($item eq 'parameter') {
1.3     ! raeburn   277:             if ($value ne '') {
        !           278:                 if (ref($Apache::lonrelrequtils::checkparms{$name}) eq 'ARRAY') {
        !           279:                     unless(grep(/^\Q$name\E$/,@{$Apache::lonrelrequtils::checkparms{$name}})) {
        !           280:                         push(@{$Apache::lonrelrequtils::checkparms{$name}},$value);
        !           281:                     }
        !           282:                 } else {
1.1       raeburn   283:                     push(@{$Apache::lonrelrequtils::checkparms{$name}},$value);
                    284:                 }
1.3     ! raeburn   285:             } elsif ($valuematch ne '') {
        !           286:                 if (ref($Apache::lonrelrequtils::checkparmsmatch{$name}) eq 'ARRAY') {
        !           287:                     unless(grep(/^\Q$name\E$/,@{$Apache::lonrelrequtils::checkparmsmatch{$name}})) {
        !           288:                         push(@{$Apache::lonrelrequtils::checkparmsmatch{$name}},$valuematch);
        !           289:                     }
        !           290:                 } else {
        !           291:                     push(@{$Apache::lonrelrequtils::checkparmsmatch{$name}},$valuematch);
        !           292:                 }
1.1       raeburn   293:             }
                    294:         } elsif ($item eq 'resourcetag') {
                    295:             if ($name eq 'responsetype') {
                    296:                 $Apache::lonrelrequtils::checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
                    297:             }
                    298:         } elsif ($item eq 'course') {
                    299:             if ($name eq 'crstype') {
                    300:                 $Apache::lonrelrequtils::checkcrstypes{$value} = $Apache::lonnet::needsrelease{$key};
                    301:             }
                    302:         }
                    303:     }
                    304:     ($Apache::lonrelrequtils::anonsurvey{major},$Apache::lonrelrequtils::anonsurvey{minor}) =
                    305:         split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                    306:     ($Apache::lonrelrequtils::randomizetry{major},$Apache::lonrelrequtils::randomizetry{minor}) =
                    307:         split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                    308:     return;
                    309: }
                    310: 
                    311: sub get_release_req {
                    312:     my ($cnum,$cdom,$crstype,$readmap,$globals_set) = @_;
                    313:     if ($readmap) {
                    314:         &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                    315:     }
                    316:     unless ($globals_set) {
                    317:         &init_global_hashes();
                    318:     }
                    319:     # check all parameters
                    320:     my ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);
                    321: 
                    322:     # check course type
                    323:     ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,$reqdmajor,
                    324:                                                       $reqdminor);
                    325:     # check communication blocks
                    326:     ($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom,$reqdmajor,$reqdminor);
                    327: 
                    328:     # check course contents
                    329:     ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,$reqdmajor,$reqdminor);
                    330:     return ($reqdmajor,$reqdminor);
                    331: }
                    332: 
                    333: sub parameter_constraints {
                    334:     my ($cnum,$cdom) = @_;
                    335:     my ($reqdmajor,$reqdminor);
                    336:     my $resourcedata=&read_paramdata($cnum,$cdom);
1.2       raeburn   337:     my $now = time;
1.1       raeburn   338:     if (ref($resourcedata) eq 'HASH') {
                    339:         foreach my $key (keys(%{$resourcedata})) {
                    340:             foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
                    341:                 if ($key =~ /(\Q$item\E)$/) {
                    342:                     if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
                    343:                         my $value = $resourcedata->{$key};
                    344:                         if ($item eq 'examcode') {
                    345:                             if (&Apache::lonnet::validCODE($value)) {
                    346:                                 $value = 'valid';
                    347:                             } else {
                    348:                                 $value = '';
                    349:                             }
1.2       raeburn   350:                         } elsif ($item eq 'printstartdate') {
                    351:                             if ($value =~ /^\d+$/) {
                    352:                                 if ($value > $now) {
                    353:                                     $value = 'future';
                    354:                                 }
                    355:                             }
                    356:                         } elsif ($item eq 'printenddate') {
                    357:                             if ($value =~ /^\d+$/) {
                    358:                                 if ($value < $now) {
                    359:                                     $value = 'past';
                    360:                                 }
                    361:                             }
1.1       raeburn   362:                         }
                    363:                         if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
1.3     ! raeburn   364:                             my ($major,$minor) = 
        !           365:                                 split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.':'});
1.1       raeburn   366:                             ($reqdmajor,$reqdminor) =
                    367:                                 &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    368:                         }
                    369:                     }
                    370:                 }
                    371:             }
1.3     ! raeburn   372:             foreach my $item (keys(%Apache::lonrelrequtils::checkparmsmatch)) { 
        !           373:                 if ($key =~ /(\Q$item\E)$/) {
        !           374:                     if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
        !           375:                         my $value = $resourcedata->{$key};
        !           376:                         foreach my $entry (@{$Apache::lonrelrequtils::checkparms{$item}}) {
        !           377:                             my $regexp;
        !           378:                             if (($item eq 'lenient') && ($entry eq 'weighted')) {
        !           379:                                 $regexp = '^[\-\.\d]+,[\-\.\d]+,[\-\.\d]+,[\-\.\d]+$';      
        !           380:                             } elsif (($item eq 'acc') && ($entry eq '_denyfrom_')) {
        !           381:                                 $regexp = '\!';
        !           382:                             }
        !           383:                             if ($regexp ne '') {
        !           384:                                 if ($value =~ /$regexp/) {
        !           385:                                     my ($major,$minor) =
        !           386:                                         split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$entry});
        !           387:                                     ($reqdmajor,$reqdminor) =
        !           388:                                         &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
        !           389:                                     last;
        !           390:                                 }
        !           391:                             }
        !           392:                         }
        !           393:                     }
        !           394:                 }
        !           395:             }
1.1       raeburn   396:         }
                    397:     }
                    398:     return ($reqdmajor,$reqdminor);
                    399: }
                    400: 
                    401: sub coursetype_constraints {
                    402:     my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_;
                    403:     if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
                    404:         my ($major,$minor) = split(/\./,$Apache::lonrelrequtils::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('comm_block',$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:                     if ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
                    435:                         my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course:commblock:printout'});
                    436:                         ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    437:                         last;
                    438:                     }
                    439:                 }
                    440:             }
                    441:         }
                    442:     }
                    443:     return ($reqdmajor,$reqdminor);
                    444: }
                    445: 
                    446: sub coursecontent_constraints {
                    447:     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
                    448:     my $navmap = Apache::lonnavmaps::navmap->new();
                    449:     if (defined($navmap)) {
                    450:         my %anonsubmissions =  &Apache::lonnet::dump('nohist_anonsurveys',
                    451:                                                      $cdom,$cnum);
                    452:         my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry',
                    453:                                                      $cdom,$cnum);
                    454:         my %allresponses;
                    455:         my ($anonsurv_subm,$randbytry_subm);
                    456:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
                    457:             my %responses = $res->responseTypes();
                    458:             foreach my $key (keys(%responses)) {
                    459:                 next unless(exists($Apache::lonrelrequtils::checkresponsetypes{$key}));
                    460:                 $allresponses{$key} += $responses{$key};
                    461:             }
                    462:             my @parts = @{$res->parts()};
                    463:             my $symb = $res->symb();
                    464:             foreach my $part (@parts) {
                    465:                 if (exists($anonsubmissions{$symb."\0".$part})) {
                    466:                     $anonsurv_subm = 1;
                    467:                 }
                    468:                 if (exists($randomizetrysubm{$symb."\0".$part})) {
                    469:                     $randbytry_subm = 1;
                    470:                 }
                    471:             }
                    472:         }
                    473:         foreach my $key (keys(%allresponses)) {
                    474:             my ($major,$minor) = split(/\./,$Apache::lonrelrequtils::checkresponsetypes{$key});
                    475:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
                    476:         }
                    477:         if ($anonsurv_subm) {
                    478:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($Apache::lonrelrequtils::anonsurvey{major},
                    479:                                           $Apache::lonrelrequtils::anonsurvey{minor},$reqdmajor,$reqdminor);
                    480:         }
                    481:         if ($randbytry_subm) {
                    482:             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($Apache::lonrelrequtils::randomizetry{major},
                    483:                                           $Apache::lonrelrequtils::randomizetry{minor},$reqdmajor,$reqdminor);
                    484:         }
                    485:     }
                    486:     return ($reqdmajor,$reqdminor);
                    487: }
                    488: 
                    489: sub update_reqd_loncaparev {
                    490:     my ($major,$minor,$reqdmajor,$reqdminor) = @_;
                    491:     if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) {
                    492:         if ($reqdmajor eq '' || $reqdminor eq '') {
                    493:             $reqdmajor = $major;
                    494:             $reqdminor = $minor;
                    495:         } elsif (($major > $reqdmajor) ||
                    496:             ($major == $reqdmajor && $minor > $reqdminor))  {
                    497:             $reqdmajor = $major;
                    498:             $reqdminor = $minor;
                    499:         }
                    500:     }
                    501:     return ($reqdmajor,$reqdminor);
                    502: }
                    503: 
                    504: sub read_paramdata {
                    505:     my ($cnum,$cdom)=@_;
                    506:     my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$cdom);
                    507:     my $classlist=&Apache::loncoursedata::get_classlist();
                    508:     foreach my $student (keys(%{$classlist})) {
                    509:         if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) {
                    510:             my ($tuname,$tudom)=($1,$2);
                    511:             my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
                    512:             foreach my $userkey (keys(%{$useropt})) {
                    513:                 if ($userkey=~/^\Q$cdom\E_\Q$cnum\E/) {
                    514:                     my $newkey=$userkey;
                    515:                     $newkey=~s/^(\Q$cdom\E_\Q$cnum\E\.)/$1\[useropt\:$tuname\:$tudom\]\./;
                    516:                     $$resourcedata{$newkey}=$$useropt{$userkey};
                    517:                 }
                    518:             }
                    519:         }
                    520:     }
                    521:     return $resourcedata;
                    522: }
                    523: 
                    524: sub modify_course_relreq {
                    525:     my ($newmajor,$newminor,$cnum,$cdom,$chome,$crstype,$cid,$readmap,$getrelreq) = @_;
                    526:     if ($cnum eq '' || $cdom eq '' || $chome eq '' || $crstype eq '' || $cid eq '') {
                    527:         $cid = $env{'request.course.id'};
                    528:         $cdom = $env{'course.'.$cid.'.domain'};
                    529:         $cnum = $env{'course.'.$cid.'.num'};
                    530:         $chome = $env{'course.'.$cid.'.home'};
                    531:         $crstype = $env{'course.'.$cid.'.type'};
                    532:         if ($crstype eq '') {
                    533:             $crstype = 'Course';
                    534:         }
                    535:     }
                    536:     if ($getrelreq) {
                    537:         ($newmajor,$newminor) = &get_release_req($cnum,$cdom,$crstype,$readmap);
                    538:     }
                    539:     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                    540:     my $needsupdate;
                    541:     if ($curr_reqd_hash{'internal.releaserequired'} eq '') {
                    542:         if (($newmajor ne '') && ($newminor ne '')) { 
                    543:             $needsupdate = 1;
                    544:         }
                    545:     } else {
                    546:         my ($currmajor,$currminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
                    547:         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
                    548:         my $serverdom = $Apache::lonnet::perlvar{'lonDefDomain'};
                    549:         my $serverrev = &Apache::lonnet::get_server_loncaparev($serverdom,$lonhost);
                    550:         my ($servermajor,$serverminor) = split(/\./,$serverrev);     
                    551:         unless (($currmajor > $servermajor) || (($currmajor == $servermajor) && ($currminor > $serverminor))) {
                    552:             if (($currmajor != $newmajor) || ($currminor != $newminor)) {
                    553:                 $needsupdate = 1;
                    554:             }
                    555:         }
                    556:     }
                    557:     if ($needsupdate) {
                    558:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
                    559:         my $result;
                    560:         if (($newmajor eq '') && ($newminor eq '')) {
                    561:             $result = &Apache::lonnet::del('environment',['internal.releaserequired'],$cdom,$cnum);
                    562:             if ($result eq 'ok') {
                    563:                 &Apache::lonnet::delenv('course.'.$cid.'.internal.releaserequired');
                    564:                 $crsinfo{$cid}{'releaserequired'} = '';
                    565:             }
                    566:         } else {
                    567:             my %needshash = (
                    568:                               'internal.releaserequired' => $newmajor.'.'.$newminor,
                    569:                             );
                    570:             $result = &Apache::lonnet::put('environment',\%needshash,$cdom,$cnum);
                    571:             if ($result eq 'ok') {
                    572:                 &Apache::lonnet::appenv({'course.'.$cid.'.internal.releaserequired' => $newmajor.'.'.$newminor});
                    573:                 if (ref($crsinfo{$cid}) eq 'HASH') {
                    574:                     $crsinfo{$cid}{'releaserequired'} = $newmajor.'.'.$newminor
                    575:                 }
                    576:             }
                    577:         }
                    578:         if ($result eq 'ok') {
                    579:             &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
                    580:         }
                    581:     }
                    582:     return;
                    583: }
                    584: 
                    585: 1;

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