Annotation of rat/lonuserstate.pm, revision 1.1
1.1 ! www 1: # The LearningOnline Network with CAPA
! 2: # Construct and maintain state and binary representation of course for user
! 3: #
! 4: # (Server for RAT Maps
! 5: #
! 6: # (Edit Handler for RAT Maps
! 7: # (TeX Content Handler
! 8: #
! 9: # 05/29/00,05/30 Gerd Kortemeyer)
! 10: # 7/1 Gerd Kortemeyer)
! 11: # 7/1,7/3,7/4,7/7,7/8,7/10 Gerd Kortemeyer)
! 12: #
! 13: # 7/15,7/17,7/18 Gerd Kortemeyer
! 14:
! 15: package Apache::lonuserstate;
! 16:
! 17: use strict;
! 18: use Apache::Constants qw(:common :http);
! 19: use Apache::File;
! 20: use HTML::TokeParser;
! 21: use Apache::lonnet();
! 22: use GDBM_File;
! 23:
! 24: # ---------------------------------------------------- Globals for this package
! 25:
! 26: my $pc; # Package counter
! 27: my %hash; # The big tied hash
! 28: my @cond; # Array with all of the conditions
! 29: my $errtext; # variable with all errors
! 30:
! 31: # --------------------------------------------------------- Loads map from disk
! 32:
! 33: sub loadmap {
! 34: my $uri=shift;
! 35: if ($hash{'map_pc_'.$uri}) { return OK; }
! 36:
! 37: $pc++;
! 38: my $lpc=$pc;
! 39: $hash{'map_pc_'.$uri}=$lpc;
! 40: $hash{'map_id_'.$lpc}=$uri;
! 41:
! 42: my $fn='/home/httpd/html'.$uri;
! 43:
! 44: unless (($fn=~/\.course$/) ||
! 45: ($fn=~/\.sequence$/) ||
! 46: ($fn=~/\.page$/)) {
! 47: $errtext.="Invalid map: $fn\n";
! 48: return OK;
! 49: }
! 50:
! 51: unless (-e $fn) {
! 52: my $returned=Apache::lonnet::repcopy($fn);
! 53: unless ($returned eq OK) {
! 54: $errtext.="Could not import: $fn - ";
! 55: if ($returned eq HTTP_SERVICE_UNAVAILABLE) {
! 56: $errtext.="Server unavailable\n";
! 57: }
! 58: if ($returned eq HTTP_NOT_FOUND) {
! 59: $errtext.="File not found\n";
! 60: }
! 61: if ($returned eq FORBIDDEN) {
! 62: $errtext.="Access forbidden\n";
! 63: }
! 64: return OK;
! 65: }
! 66: }
! 67:
! 68: if (-e $fn) {
! 69: my @content;
! 70: {
! 71: my $fh=Apache::File->new($fn);
! 72: @content=<$fh>;
! 73: }
! 74: my $instr=join('',@content);
! 75: my $parser = HTML::TokeParser->new(\$instr);
! 76: my $token;
! 77:
! 78: my $linkpc=0;
! 79:
! 80: $fn=~/\.(\w+)$/;
! 81:
! 82: $hash{'map_type_'.$lpc}=$1;
! 83:
! 84: while ($token = $parser->get_token) {
! 85: if ($token->[0] eq 'S') {
! 86: if ($token->[1] eq 'resource') {
! 87: # -------------------------------------------------------------------- Resource
! 88:
! 89: my $rid=$lpc.'.'.$token->[2]->{'id'};
! 90:
! 91: $hash{'kind_'.$rid}='res';
! 92: $hash{'title_'.$rid}=$token->[2]->{'title'};
! 93: my $turi=$token->[2]->{'src'};
! 94: $hash{'src_'.$rid}=$turi;
! 95:
! 96: if (defined($hash{'ids_'.$turi})) {
! 97: $hash{'ids_'.$turi}.=','.$rid;
! 98: } else {
! 99: $hash{'ids_'.$turi}=''.$rid;
! 100: }
! 101:
! 102: if ($token->[2]->{'src'}=~/\/\//) {
! 103: $hash{'ext_'.$rid}='true:';
! 104: } else {
! 105: $hash{'ext_'.$rid}='false:';
! 106: }
! 107: if ($token->[2]->{'type'}) {
! 108: $hash{'type_'.$rid}=$token->[2]->{'type'};
! 109: } else {
! 110: $hash{'type_'.$rid}='normal';
! 111: }
! 112:
! 113: if (($turi=~/\.course$/) ||
! 114: ($turi=~/\.sequence$/) ||
! 115: ($turi=~/\.page$/)) {
! 116: &loadmap($turi);
! 117: }
! 118:
! 119: } elsif ($token->[1] eq 'condition') {
! 120: # ------------------------------------------------------------------- Condition
! 121:
! 122: my $rid=$lpc.'.'.$token->[2]->{'id'};
! 123:
! 124: $hash{'kind_'.$rid}='cond';
! 125: $hash{'value_'.$rid}=$token->[2]->{'value'};
! 126: if ($token->[2]->{'type'}) {
! 127: $hash{'type_'.$rid}=$token->[2]->{'type'};
! 128: } else {
! 129: $hash{'type_'.$rid}='normal';
! 130: }
! 131:
! 132: } elsif ($token->[1] eq 'link') {
! 133: # ----------------------------------------------------------------------- Links
! 134:
! 135: $linkpc++;
! 136: my $linkid=$lpc.'.'.$linkpc;
! 137:
! 138: my $goesto=$lpc.'.'.$token->[2]->{'to'};
! 139: my $comesfrom=$lpc.'.'.$token->[2]->{'from'};
! 140: my $undercond=0;
! 141:
! 142: if ($token->[2]->{'condition'}) {
! 143: $undercond=$lpc.'.'.$token->[2]->{'condition'};
! 144: }
! 145:
! 146: $hash{'goesto_'.$linkid}=$goesto;
! 147: $hash{'comesfrom_'.$linkid}=$comesfrom;
! 148: $hash{'undercond_'.$linkid}=$undercond;
! 149:
! 150: if (defined($hash{'to_'.$comesfrom})) {
! 151: $hash{'to_'.$comesfrom}.=','.$linkid;
! 152: } else {
! 153: $hash{'to_'.$comesfrom}=''.$linkid;
! 154: }
! 155: if (defined($hash{'from_'.$goesto})) {
! 156: $hash{'from_'.$goesto}.=','.$linkid;
! 157: } else {
! 158: $hash{'from_'.$goesto}=''.$linkid;
! 159: }
! 160: }
! 161:
! 162: }
! 163: }
! 164:
! 165: } else {
! 166: $errtext.='Map not loaded: The file does not exist. ';
! 167: }
! 168: }
! 169:
! 170:
! 171: # ---------------------------------------------------- Read map and all submaps
! 172:
! 173: sub readmap {
! 174: my $uri=shift;
! 175: @cond=();
! 176: %hash=();
! 177: $errtext='';
! 178: $pc=0;
! 179: loadmap($uri);
! 180: }
! 181:
! 182: sub handler {
! 183: my $r = shift;
! 184: $r->content_type('text/html');
! 185: $r->send_http_header;
! 186: return OK if $r->header_only;
! 187: readmap('/res/msu/korte/foo.course');
! 188: $r->print("<html><body>\n");
! 189: my $hashkey;
! 190: foreach $hashkey (keys %hash) {
! 191: $r->print("$hashkey: $hash{$hashkey}<br>\n");
! 192: }
! 193: $r->print("<h1>$errtext</h1></body></html>\n");
! 194: return OK;
! 195: }
! 196:
! 197:
! 198:
! 199: 1;
! 200: __END__
! 201:
! 202:
! 203:
! 204:
! 205:
! 206:
! 207:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>