Annotation of rat/lonuserstate.pm, revision 1.50
1.1 www 1: # The LearningOnline Network with CAPA
2: # Construct and maintain state and binary representation of course for user
3: #
1.50 ! albertel 4: # $Id: lonuserstate.pm,v 1.49 2003/02/03 18:03:53 harris41 Exp $
1.25 www 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: #
1.1 www 28: # (Server for RAT Maps
29: #
30: # (Edit Handler for RAT Maps
31: # (TeX Content Handler
32: #
1.26 harris41 33: # YEAR=2000
1.1 www 34: # 05/29/00,05/30 Gerd Kortemeyer)
35: # 7/1 Gerd Kortemeyer)
36: # 7/1,7/3,7/4,7/7,7/8,7/10 Gerd Kortemeyer)
37: #
1.9 www 38: # 7/15,7/17,7/18,8/1,8/2,8/4,8/5,8/21,8/22,8/23,8/30,
1.19 www 39: # 9/2,9/4,9/29,9/30,10/2,10/11,10/30,10/31,
1.22 www 40: # 11/1,11/2,11/14,11/16,11/22,12/28,
1.26 harris41 41: # YEAR=2001
1.24 www 42: # 07/05/01,08/30,08/31 Gerd Kortemeyer
1.26 harris41 43: #
44: ###
1.1 www 45:
46: package Apache::lonuserstate;
47:
1.26 harris41 48: # ------------------------------------------------- modules used by this module
1.1 www 49: use strict;
50: use Apache::Constants qw(:common :http);
51: use Apache::File;
52: use HTML::TokeParser;
53: use Apache::lonnet();
1.26 harris41 54: use Apache::loncommon();
1.1 www 55: use GDBM_File;
1.12 www 56: use Apache::lonmsg;
1.15 www 57: use Safe;
1.21 www 58: use Safe::Hole;
1.15 www 59: use Opcode;
60:
1.1 www 61: # ---------------------------------------------------- Globals for this package
62:
63: my $pc; # Package counter
64: my %hash; # The big tied hash
1.19 www 65: my %parmhash;# The hash with the parameters
1.1 www 66: my @cond; # Array with all of the conditions
67: my $errtext; # variable with all errors
1.21 www 68: my $retfurl; # variable with the very first URL in the course
1.29 www 69: my %randompick; # randomly picked resources
1.45 www 70: my %actualversion; # version of resource as loaded now
71: my %setversion; # forced version of resource
72: my %lastversion; # version when CC came in last
73: my $versionmode; # how versioning is handled in this course
74:
1.1 www 75: # --------------------------------------------------------- Loads map from disk
76:
77: sub loadmap {
78: my $uri=shift;
79: if ($hash{'map_pc_'.$uri}) { return OK; }
80:
81: $pc++;
82: my $lpc=$pc;
83: $hash{'map_pc_'.$uri}=$lpc;
84: $hash{'map_id_'.$lpc}=$uri;
85:
1.37 www 86: # Determine and check filename
87: my $fn=&Apache::lonnet::filelocation('',$uri);
88:
89: my $ispage=($fn=~/\.page$/);
1.1 www 90:
1.10 www 91: unless (($fn=~/\.sequence$/) ||
1.1 www 92: ($fn=~/\.page$/)) {
93: $errtext.="Invalid map: $fn\n";
94: return OK;
95: }
96:
1.37 www 97: my $instr=&Apache::lonnet::getfile($fn);
98:
99: unless ($instr == -1) {
1.22 www 100:
1.37 www 101: # Successfully got file, parse it
1.1 www 102:
103: my $parser = HTML::TokeParser->new(\$instr);
104: my $token;
105:
106: my $linkpc=0;
107:
108: $fn=~/\.(\w+)$/;
109:
110: $hash{'map_type_'.$lpc}=$1;
111:
112: while ($token = $parser->get_token) {
113: if ($token->[0] eq 'S') {
114: if ($token->[1] eq 'resource') {
115: # -------------------------------------------------------------------- Resource
116:
117: my $rid=$lpc.'.'.$token->[2]->{'id'};
118:
119: $hash{'kind_'.$rid}='res';
120: $hash{'title_'.$rid}=$token->[2]->{'title'};
121: my $turi=$token->[2]->{'src'};
1.47 www 122: $Apache::lonnet::titlecache{
123: &Apache::lonnet::symbclean(
124: &Apache::lonnet::declutter($uri).'___'.
125: $token->[2]->{'id'}.'___'.
126: &Apache::lonnet::declutter($turi))}=
127: $token->[2]->{'title'};
1.22 www 128: unless ($ispage) {
129: $turi=~/\.(\w+)$/;
1.26 harris41 130: my $embstyle=&Apache::loncommon::fileembstyle($1);
1.40 www 131: if ($token->[2]->{'external'} eq 'true') { # external
1.22 www 132: $turi=~s/^http\:\/\//\/adm\/wrapper\/ext\//;
1.40 www 133: } elsif ($turi=~/^\/*uploaded\//) { # uploaded
134: if (($embstyle eq 'img') || ($embstyle eq 'emb')
135: || ($embstyle eq 'ssi')) {
136: $turi='/adm/wrapper'.$turi;
1.41 www 137: } elsif ($turi!~/\.(sequence|page)$/) {
1.42 www 138: $turi='/adm/coursedocs/showdoc'.$turi;
1.40 www 139: }
140: } else { # normal internal resource
1.39 www 141: if (($embstyle eq 'img') || ($embstyle eq 'emb')
1.43 www 142: || ($turi=~/\/(syllabus|aboutme|navmaps|smppg|bulletinboard)$/)) {
1.22 www 143: $turi='/adm/wrapper'.$turi;
144: }
145: }
146: }
1.1 www 147: $hash{'src_'.$rid}=$turi;
148:
149: if (defined($hash{'ids_'.$turi})) {
150: $hash{'ids_'.$turi}.=','.$rid;
151: } else {
152: $hash{'ids_'.$turi}=''.$rid;
153: }
154:
1.22 www 155: if ($token->[2]->{'external'} eq 'true') {
1.1 www 156: $hash{'ext_'.$rid}='true:';
157: } else {
158: $hash{'ext_'.$rid}='false:';
159: }
160: if ($token->[2]->{'type'}) {
161: $hash{'type_'.$rid}=$token->[2]->{'type'};
1.2 www 162: if ($token->[2]->{'type'} eq 'start') {
163: $hash{'map_start_'.$uri}="$rid";
164: }
165: if ($token->[2]->{'type'} eq 'finish') {
166: $hash{'map_finish_'.$uri}="$rid";
167: }
1.1 www 168: } else {
169: $hash{'type_'.$rid}='normal';
170: }
171:
1.10 www 172: if (($turi=~/\.sequence$/) ||
1.1 www 173: ($turi=~/\.page$/)) {
1.2 www 174: $hash{'is_map_'.$rid}=1;
1.1 www 175: &loadmap($turi);
176: }
177:
178: } elsif ($token->[1] eq 'condition') {
179: # ------------------------------------------------------------------- Condition
180:
181: my $rid=$lpc.'.'.$token->[2]->{'id'};
182:
183: $hash{'kind_'.$rid}='cond';
1.2 www 184: $cond[$#cond+1]=$token->[2]->{'value'};
185: $hash{'condid_'.$rid}=$#cond;
1.1 www 186: if ($token->[2]->{'type'}) {
1.2 www 187: $cond[$#cond].=':'.$token->[2]->{'type'};
1.1 www 188: } else {
1.2 www 189: $cond[$#cond].=':normal';
1.1 www 190: }
191:
192: } elsif ($token->[1] eq 'link') {
193: # ----------------------------------------------------------------------- Links
194:
195: $linkpc++;
196: my $linkid=$lpc.'.'.$linkpc;
197:
198: my $goesto=$lpc.'.'.$token->[2]->{'to'};
199: my $comesfrom=$lpc.'.'.$token->[2]->{'from'};
200: my $undercond=0;
201:
202: if ($token->[2]->{'condition'}) {
203: $undercond=$lpc.'.'.$token->[2]->{'condition'};
204: }
205:
206: $hash{'goesto_'.$linkid}=$goesto;
207: $hash{'comesfrom_'.$linkid}=$comesfrom;
208: $hash{'undercond_'.$linkid}=$undercond;
209:
210: if (defined($hash{'to_'.$comesfrom})) {
211: $hash{'to_'.$comesfrom}.=','.$linkid;
212: } else {
213: $hash{'to_'.$comesfrom}=''.$linkid;
214: }
215: if (defined($hash{'from_'.$goesto})) {
216: $hash{'from_'.$goesto}.=','.$linkid;
217: } else {
218: $hash{'from_'.$goesto}=''.$linkid;
219: }
1.18 www 220: } elsif ($token->[1] eq 'param') {
221: # ------------------------------------------------------------------- Parameter
222:
223: my $referid=$lpc.'.'.$token->[2]->{'to'};
1.20 www 224: my $part=$token->[2]->{'part'};
225: unless ($part) { $part=0; }
1.18 www 226: my $newparam=
227: &Apache::lonnet::escape($token->[2]->{'type'}).':'.
1.20 www 228: &Apache::lonnet::escape($part.'.'.
229: $token->[2]->{'name'}).'='.
1.18 www 230: &Apache::lonnet::escape($token->[2]->{'value'});
231: if (defined($hash{'param_'.$referid})) {
232: $hash{'param_'.$referid}.='&'.$newparam;
233: } else {
234: $hash{'param_'.$referid}=''.$newparam;
235: }
1.29 www 236: if ($token->[2]->{'name'} eq 'parameter_mapalias') {
1.28 www 237: $hash{'mapalias_'.$token->[2]->{'value'}}=$referid;
238: }
1.29 www 239: if ($token->[2]->{'name'} eq 'parameter_randompick') {
240: $randompick{$referid}=$token->[2]->{'value'};
241: }
1.1 www 242: }
243:
244: }
245: }
246:
247: } else {
248: $errtext.='Map not loaded: The file does not exist. ';
249: }
250: }
251:
1.3 www 252: # --------------------------------------------------------- Simplify expression
253:
254: sub simplify {
255: my $expression=shift;
256: # (8)=8
257: $expression=~s/\((\d+)\)/$1/g;
258: # 8&8=8
1.7 www 259: $expression=~s/(\D)(\d+)\&\2(\D)/$1$2$3/g;
1.3 www 260: # 8|8=8
1.7 www 261: $expression=~s/(\D)(\d+)\|\2(\D)/$1$2$3/g;
1.3 www 262: # (5&3)&4=5&3&4
1.7 www 263: $expression=~s/\((\d+)((?:\&\d+)+)\)\&(\d+\D)/$1$2\&$3/g;
1.3 www 264: # (((5&3)|(4&6)))=((5&3)|(4&6))
265: $expression=~
266: s/\((\(\(\d+(?:\&\d+)*\)(?:\|\(\d+(?:\&\d+)*\))+\))\)/$1/g;
267: # ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2)
268: $expression=~
269: s/\((\(\d+(?:\&\d+)*\))((?:\|\(\d+(?:\&\d+)*\))+)\)\|(\(\d+(?:\&\d+)*\))/\($1$2\|$3\)/g;
270: return $expression;
271: }
272:
1.2 www 273: # -------------------------------------------------------- Build condition hash
274:
275: sub traceroute {
1.3 www 276: my ($sofar,$rid,$beenhere)=@_;
277: $sofar=simplify($sofar);
1.2 www 278: unless ($beenhere=~/\&$rid\&/) {
279: $beenhere.=$rid.'&';
1.48 www 280: if (($retfurl eq '') && ($hash{'src_'.$rid})
281: && ($hash{'src_'.$rid}!~/\.sequence$/)) {
1.29 www 282: my ($mapid,$resid)=split(/\./,$rid);
1.35 www 283: $retfurl=$hash{'src_'.$rid}.
284: (($hash{'src_'.$rid}=~/\?/)?'&':'?').'symb='.
1.29 www 285: &Apache::lonnet::symbclean(
286: &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
287: '___'.$resid.'___'.
288: &Apache::lonnet::declutter($hash{'src_'.$rid}));
1.21 www 289: }
1.2 www 290: if (defined($hash{'conditions_'.$rid})) {
1.3 www 291: $hash{'conditions_'.$rid}=simplify(
292: '('.$hash{'conditions_'.$rid}.')|('.$sofar.')');
1.2 www 293: } else {
294: $hash{'conditions_'.$rid}=$sofar;
295: }
296: if (defined($hash{'is_map_'.$rid})) {
1.3 www 297: if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) {
298: &traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&');
299: if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) {
300: $sofar=
301: $hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}};
302: }
1.2 www 303: }
304: }
305: if (defined($hash{'to_'.$rid})) {
1.26 harris41 306: foreach (split(/\,/,$hash{'to_'.$rid})) {
1.2 www 307: my $further=$sofar;
308: if ($hash{'undercond_'.$_}) {
309: if (defined($hash{'condid_'.$hash{'undercond_'.$_}})) {
1.3 www 310: $further=simplify('('.$further.')&('.
311: $hash{'condid_'.$hash{'undercond_'.$_}}.')');
1.2 www 312: } else {
313: $errtext.='Undefined condition ID: '
314: .$hash{'undercond_'.$_}.'. ';
315: }
316: }
317: &traceroute($further,$hash{'goesto_'.$_},$beenhere);
1.26 harris41 318: }
1.2 www 319: }
320: }
321: }
1.1 www 322:
1.19 www 323: # ------------------------------ Cascading conditions, quick access, parameters
1.4 www 324:
325: sub accinit {
326: my ($uri,$short,$fn)=@_;
327: my %acchash=();
328: my %captured=();
329: my $condcounter=0;
1.5 www 330: $acchash{'acc.cond.'.$short.'.0'}=0;
1.26 harris41 331: foreach (keys %hash) {
1.4 www 332: if ($_=~/^conditions/) {
333: my $expr=$hash{$_};
1.26 harris41 334: foreach ($expr=~m/(\(\(\d+(?:\&\d+)+\)(?:\|\(\d+(?:\&\d+)+\))+\))/g) {
1.4 www 335: my $sub=$_;
336: my $orig=$_;
1.13 www 337: $sub=~/\(\((\d+\&(:?\d+\&)*)(?:\d+\&*)+\)(?:\|\(\1(?:\d+\&*)+\))+\)/;
1.4 www 338: my $factor=$1;
1.7 www 339: $sub=~s/$factor//g;
340: $sub=~s/^\(/\($factor\(/;
1.4 www 341: $sub.=')';
342: $sub=simplify($sub);
343: $orig=~s/(\W)/\\$1/g;
1.7 www 344: $expr=~s/$orig/$sub/;
1.26 harris41 345: }
1.4 www 346: $hash{$_}=$expr;
347: unless (defined($captured{$expr})) {
348: $condcounter++;
349: $captured{$expr}=$condcounter;
1.5 www 350: $acchash{'acc.cond.'.$short.'.'.$condcounter}=$expr;
1.4 www 351: }
1.19 www 352: } elsif ($_=~/^param_(\d+)\.(\d+)/) {
353: my $prefix=&Apache::lonnet::declutter($hash{'map_id_'.$1}).
354: '___'.$2.'___'.&Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
1.26 harris41 355: foreach (split(/\&/,$hash{$_})) {
1.19 www 356: my ($typename,$value)=split(/\=/,$_);
357: my ($type,$name)=split(/\:/,$typename);
358: $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name)}=
359: &Apache::lonnet::unescape($value);
360: $parmhash{$prefix.'.'.&Apache::lonnet::unescape($name).'.type'}=
361: &Apache::lonnet::unescape($type);
1.26 harris41 362: }
1.19 www 363: }
1.26 harris41 364: }
365: foreach (keys %hash) {
1.4 www 366: if ($_=~/^ids/) {
1.26 harris41 367: foreach (split(/\,/,$hash{$_})) {
1.13 www 368: my $resid=$_;
1.4 www 369: my $uri=$hash{'src_'.$resid};
1.22 www 370: $uri=~s/^\/adm\/wrapper//;
1.4 www 371: my @uriparts=split(/\//,$uri);
372: my $urifile=$uriparts[$#uriparts];
373: $#uriparts--;
374: my $uripath=join('/',@uriparts);
1.8 www 375: $uripath=~s/^\/res\///;
1.23 www 376: if ($uripath) {
1.13 www 377: my $uricond='0';
1.4 www 378: if (defined($hash{'conditions_'.$resid})) {
1.13 www 379: $uricond=$captured{$hash{'conditions_'.$resid}};
1.4 www 380: }
1.5 www 381: if (defined($acchash{'acc.res.'.$short.'.'.$uripath})) {
1.13 www 382: if ($acchash{'acc.res.'.$short.'.'.$uripath}=~
383: /(\&$urifile\:[^\&]*)/) {
384: my $replace=$1;
1.27 www 385: my $regexp=$replace;
386: $regexp=~s/\|/\\\|/g;
1.13 www 387: $acchash{'acc.res.'.$short.'.'.$uripath}
1.27 www 388: =~s/$regexp/$replace\|$uricond/;
1.13 www 389: } else {
390: $acchash{'acc.res.'.$short.'.'.$uripath}.=
391: $urifile.':'.$uricond.'&';
392: }
1.4 www 393: } else {
1.13 www 394: $acchash{'acc.res.'.$short.'.'.$uripath}=
395: '&'.$urifile.':'.$uricond.'&';
1.23 www 396: }
397: }
1.26 harris41 398: }
1.13 www 399: }
1.26 harris41 400: }
1.24 www 401: $acchash{'acc.res.'.$short.'.'}='&:0&';
1.8 www 402: my $courseuri=$uri;
403: $courseuri=~s/^\/res\///;
1.19 www 404: &Apache::lonnet::delenv('(acc\.|httpref\.)');
1.4 www 405: &Apache::lonnet::appenv(%acchash,
1.9 www 406: "request.course.id" => $short,
1.8 www 407: "request.course.fn" => $fn,
408: "request.course.uri" => $courseuri);
1.4 www 409: }
410:
1.29 www 411: # ------------------------------------- Selectively delete from randompick maps
412:
413: sub pickrandom {
1.31 www 414: my $randomoutentry='';
1.29 www 415: foreach my $rid (keys %randompick) {
416: my $rndpick=$randompick{$rid};
417: my $mpc=$hash{'map_pc_'.$hash{'src_'.$rid}};
418: # ------------------------------------------- put existing resources into array
419: my @currentrids=();
1.50 ! albertel 420: foreach (sort(keys(%hash))) {
1.29 www 421: if ($_=~/^src_($mpc\.\d+)/) {
422: if ($hash{'src_'.$1}) { push @currentrids, $1; }
423: }
424: }
1.50 ! albertel 425: # rids are number.number and we want to numercially sort on
! 426: # the second number
! 427: @currentrids=sort {
! 428: my (undef,$aid)=split(/\./,$a);
! 429: my (undef,$bid)=split(/\./,$b);
! 430: $aid <=> $bid;
! 431: } @currentrids;
1.29 www 432: next if ($#currentrids<$rndpick);
433: # -------------------------------- randomly eliminate the ones that should stay
1.50 ! albertel 434: my (undef,$id)=split(/\./,$rid);
! 435: my $rndseed=&Apache::lonnet::rndseed($id); # use id instead of symb
! 436: &Math::Random::random_set_seed_from_phrase($rndseed);
! 437: my @whichids=&Math::Random::random_permuted_index($#currentrids+1);
! 438: for (my $i=1;$i<=$rndpick;$i++) { $currentrids[$whichids[$i]]=''; }
! 439: #&Apache::lonnet::logthis("$id,$rndseed,".join(':',@whichids));
1.29 www 440: # -------------------------------------------------------- delete the leftovers
441: for (my $k=0; $k<=$#currentrids; $k++) {
442: if ($currentrids[$k]) {
443: $hash{'randomout_'.$currentrids[$k]}=1;
1.32 www 444: my ($mapid,$resid)=split(/\./,$currentrids[$k]);
445: $randomoutentry.='&'.
446: &Apache::lonnet::symbclean(
447: &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
448: '___'.$resid.'___'.
449: &Apache::lonnet::declutter($hash{'src_'.$currentrids[$k]})
450: ).'&';
1.29 www 451: }
452: }
1.31 www 453: }
454: if ($randomoutentry) {
455: &Apache::lonnet::appenv('acc.randomout' => $randomoutentry);
1.29 www 456: }
457: }
458:
1.1 www 459: # ---------------------------------------------------- Read map and all submaps
460:
461: sub readmap {
1.9 www 462: my $short=shift;
463: $short=~s/^\///;
464: my %cenv=&Apache::lonnet::coursedescription($short);
465: my $fn=$cenv{'fn'};
466: my $uri;
467: $short=~s/\//\_/g;
468: unless ($uri=$cenv{'url'}) {
469: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
470: "Could not load course $short.</font>");
471: return 'No course data available.';
472: }
1.3 www 473: @cond=('true:normal');
1.11 www 474: unlink($fn.'.db');
475: unlink($fn.'_symb.db');
476: unlink($fn.'.state');
1.19 www 477: unlink($fn.'parms.db');
1.29 www 478: undef %randompick;
1.21 www 479: $retfurl='';
1.36 albertel 480: if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) &&
481: (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) {
1.4 www 482: %hash=();
1.19 www 483: %parmhash=();
1.4 www 484: $errtext='';
485: $pc=0;
1.38 www 486: my $furi=&Apache::lonnet::clutter($uri);
1.30 www 487: $hash{'src_0.0'}=$furi;
488: $hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
489: $hash{'ids_'.$furi}='0.0';
490: $hash{'is_map_0.0'}=1;
1.4 www 491: loadmap($uri);
492: if (defined($hash{'map_start_'.$uri})) {
493: &traceroute('0',$hash{'map_start_'.$uri},'&');
494: &accinit($uri,$short,$fn);
1.29 www 495: &pickrandom();
1.45 www 496: }
497: # ------------------------------------------------------------ Version tracking
1.48 www 498: # if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
499: # &Apache::lonnet::logthis('Will be version tracking');
500: # }
1.19 www 501: unless ((untie(%hash)) && (untie(%parmhash))) {
1.4 www 502: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
503: "Could not untie coursemap $fn for $uri.</font>");
1.1 www 504: }
1.4 www 505: {
506: my $cfh;
507: if ($cfh=Apache::File->new(">$fn.state")) {
508: print $cfh join("\n",@cond);
509: } else {
1.6 www 510: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
1.4 www 511: "Could not write statemap $fn for $uri.</font>");
512: }
513: }
514: } else {
1.6 www 515: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
1.4 www 516: "Could not tie coursemap $fn for $uri.</font>");
517: }
1.12 www 518: &Apache::lonmsg::author_res_msg($ENV{'request.course.uri'},$errtext);
1.46 www 519: # ------------------------------------------------- Check for critical messages
520:
521: my @what=&Apache::lonnet::dump('critical',$ENV{'user.domain'},
522: $ENV{'user.name'});
523: if ($what[0]) {
524: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
525: $retfurl='/adm/email?critical=display';
526: }
527: }
1.21 www 528: return ($retfurl,$errtext);
1.1 www 529: }
1.15 www 530:
531: # ------------------------------------------------------- Evaluate state string
532:
533: sub evalstate {
1.21 www 534:
1.15 www 535: my $fn=$ENV{'request.course.fn'}.'.state';
536: my $state='2';
537: if (-e $fn) {
538: my @conditions=();
539: {
540: my $fh=Apache::File->new($fn);
541: @conditions=<$fh>;
542: }
1.21 www 543: my $safeeval = new Safe;
544: my $safehole = new Safe::Hole;
1.15 www 545: $safeeval->permit("entereval");
546: $safeeval->permit(":base_math");
547: $safeeval->deny(":base_io");
1.21 www 548: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.26 harris41 549: foreach (@conditions) {
1.15 www 550: my $line=$_;
551: chomp($line);
552: my ($condition,$weight)=split(/\:/,$_);
553: if ($safeeval->reval($condition)) {
554: if ($weight eq 'force') {
555: $state.='3';
556: } else {
557: $state.='2';
558: }
559: } else {
560: if ($weight eq 'stop') {
561: $state.='0';
562: } else {
563: $state.='1';
564: }
565: }
1.26 harris41 566: }
1.15 www 567: }
568: &Apache::lonnet::appenv('user.state.'.$ENV{'request.course.id'} => $state);
569: return $state;
570: }
571:
1.1 www 572: 1;
573: __END__
574:
1.26 harris41 575: =head1 NAME
576:
577: Apache::lonuserstate - Construct and maintain state and binary representation
578: of course for user
579:
580: =head1 SYNOPSIS
581:
582: Invoked by lonroles.pm.
583:
584: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
585:
586: =head1 INTRODUCTION
587:
588: This module constructs and maintains state and binary representation
589: of course for user.
590:
591: This is part of the LearningOnline Network with CAPA project
592: described at http://www.lon-capa.org.
593:
594: =head1 HANDLER SUBROUTINE
595:
596: There is no handler subroutine.
597:
598: =head1 OTHER SUBROUTINES
599:
600: =over 4
601:
602: =item *
603:
604: loadmap() : Loads map from disk
605:
606: =item *
607:
608: simplify() : Simplify expression
609:
610: =item *
611:
612: traceroute() : Build condition hash
613:
614: =item *
615:
616: accinit() : Cascading conditions, quick access, parameters
1.1 www 617:
1.26 harris41 618: =item *
1.1 www 619:
1.26 harris41 620: readmap() : Read map and all submaps
1.1 www 621:
1.26 harris41 622: =item *
1.1 www 623:
1.26 harris41 624: evalstate() : Evaluate state string
1.1 www 625:
1.26 harris41 626: =back
1.1 www 627:
1.26 harris41 628: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>