Annotation of loncom/imspackages/imsprocessor.pm, revision 1.35
1.10 raeburn 1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23:
1.1 raeburn 24: package Apache::imsprocessor;
25:
26: use Apache::lonnet;
1.21 www 27: use Apache::loncleanup;
1.20 raeburn 28: use LWP::UserAgent;
29: use HTTP::Request::Common;
1.1 raeburn 30: use LONCAPA::Configuration;
1.2 raeburn 31: use strict;
1.3 raeburn 32:
33: sub ims_config {
34: my ($areas,$cmsmap,$areaname) = @_;
1.35 ! raeburn 35: @{$areas} = ("doc","extlink","announce","staff","board","quiz","survey","pool","users","question");
1.3 raeburn 36: %{$$cmsmap{bb5}} = (
37: announce => 'resource/x-bb-announcement',
38: board => 'resource/x-bb-discussionboard',
39: doc => 'resource/x-bb-document',
40: extlink => 'resource/x-bb-externallink',
41: pool => 'assessment/x-bb-pool',
42: quiz => 'assessment/x-bb-quiz',
43: staff => 'resource/x-bb-staffinfo',
44: survey => 'assessment/x-bb-survey',
45: users => 'course/x-bb-user',
46: );
1.30 raeburn 47: %{$$cmsmap{bb6}} = (
48: announce => 'resource/x-bb-announcement',
49: board => 'resource/x-bb-discussionboard',
50: doc => 'resource/x-bb-document',
51: extlink => 'resource/x-bb-externallink',
52: pool => 'assessment/x-bb-qti-pool',
53: quiz => 'assessment/x-bb-qti-test',
54: staff => 'resource/x-bb-staffinfo',
55: survey => 'assessment/x-bb-survey',
56: users => 'course/x-bb-user',
57: );
1.10 raeburn 58: $$cmsmap{bb6}{conference} = 'resource/x-bb-conference';
1.3 raeburn 59: %{$$cmsmap{angel}} = (
60: board => 'BOARD',
61: extlink => 'LINK',
62: msg => 'MESSAGE',
63: quiz => 'QUIZ',
64: survey => 'FORM',
65: );
66: @{$$cmsmap{angel}{doc}} = ('FILE','PAGE');
1.34 raeburn 67: %{$$cmsmap{webctce4}} = (
1.15 raeburn 68: quiz => 'webctquiz',
69: survey => 'webctsurvey',
70: doc => 'webcontent'
71: );
1.35 ! raeburn 72: %{$$cmsmap{webctvista4}} = (
! 73: question => 'webct.question',
! 74: quiz => 'webct.assessment',
! 75: survey => 'webctsurvey',
! 76: doc => 'webcontent'
! 77: );
1.3 raeburn 78: %{$areaname} = (
79: announce => 'Announcements',
80: board => 'Discussion Boards',
81: doc => 'Documents, pages, and folders',
82: extlink => 'Links to external sites',
83: pool => 'Question pools',
84: quiz => 'Quizzes',
1.35 ! raeburn 85: question => 'Assessment Questions',
1.3 raeburn 86: staff => 'Staff information',
87: survey => 'Surveys',
88: users => 'Enrollment',
89: );
90: }
1.1 raeburn 91:
92: sub create_tempdir {
1.3 raeburn 93: my ($context,$pathinfo,$timenow) = @_;
1.1 raeburn 94: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
95: my $tempdir;
1.3 raeburn 96: if ($context eq 'DOCS') {
1.1 raeburn 97: $tempdir = $$configvars{'lonDaemons'}.'/tmp/'.$pathinfo;
98: if (!-e "$tempdir") {
1.2 raeburn 99: mkdir("$tempdir",0770);
100: }
101: $tempdir .= '/'.$timenow;
102: if (!-e "$tempdir") {
103: mkdir("$tempdir",0770);
104: }
1.3 raeburn 105: } elsif ($context eq "CSTR") {
1.1 raeburn 106: if (!-e "$pathinfo/temp") {
1.2 raeburn 107: mkdir("$pathinfo/temp",0770);
1.1 raeburn 108: }
109: $tempdir = $pathinfo.'/temp';
110: }
111: return $tempdir;
112: }
113:
1.3 raeburn 114: sub uploadzip {
115: my ($context,$tempdir,$source) = @_;
116: my $fname;
117: if ($context eq 'DOCS') {
1.19 albertel 118: $fname=$env{'form.uploadname.filename'};
1.3 raeburn 119: # Replace Windows backslashes by forward slashes
120: $fname=~s/\\/\//g;
121: # Get rid of everything but the actual filename
122: $fname=~s/^.*\/([^\/]+)$/$1/;
123: # Replace spaces by underscores
124: $fname=~s/\s+/\_/g;
125: # Replace all other weird characters by nothing
126: $fname=~s/[^\w\.\-]//g;
127: # See if there is anything left
128: unless ($fname) { return 'error: no uploaded file'; }
129: # Save the file
1.19 albertel 130: chomp($env{'form.uploadname'});
1.3 raeburn 131: open(my $fh,'>'.$tempdir.'/'.$fname);
1.19 albertel 132: print $fh $env{'form.uploadname'};
1.3 raeburn 133: close($fh);
134: } elsif ($context eq 'CSTR') {
135: if ($source =~ m/\/([^\/]+)$/) {
136: $fname = $1;
137: my $destination = $tempdir.'/'.$fname;
138: rename($source,$destination);
139: }
140: }
141: return $fname;
142: }
143:
1.1 raeburn 144: sub expand_zip {
145: my ($tempdir,$filename) = @_;
146: my $zipfile = "$tempdir/$filename";
1.10 raeburn 147: if (!-e "$zipfile") {
148: return 'no zip';
149: }
1.1 raeburn 150: if ($filename =~ m|\.zip$|i) {
151: open(OUTPUT, "unzip -o $zipfile -d $tempdir 2> /dev/null |");
152: close(OUTPUT);
153: } else {
154: return 'nozip';
155: }
156: if ($filename =~ m|\.zip$|i) {
157: unlink($zipfile);
158: }
159: return 'ok';
160: }
161:
162: sub process_manifest {
1.14 raeburn 163: my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo,$phase,$includedres,$includeditems) = @_;
1.1 raeburn 164: my %toc = (
1.10 raeburn 165: bb6 => 'organization',
1.1 raeburn 166: bb5 => 'tableofcontents',
167: angel => 'organization',
1.34 raeburn 168: webctce4 => 'organization',
1.35 ! raeburn 169: webctvista4 => 'organization'
1.1 raeburn 170: );
171: my @seq = "Top";
1.2 raeburn 172: %{$$items{'Top'}} = (
173: contentscount => 0,
174: resnum => 'toplevel',
175: );
1.3 raeburn 176: %{$$resources{'toplevel'}} = (
177: revitm => 'Top'
178: );
1.2 raeburn 179:
180: if ($cms eq 'angel') {
181: $$resources{'toplevel'}{type} = "FOLDER";
1.10 raeburn 182: } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
1.2 raeburn 183: $$resources{'toplevel'}{type} = 'resource/x-bb-document';
1.14 raeburn 184: } else {
185: $$resources{'toplevel'}{type} = 'webcontent';
1.2 raeburn 186: }
187:
1.1 raeburn 188: unless (-e "$tempdir/imsmanifest.xml") {
189: return 'nomanifest';
1.17 raeburn 190: }
1.1 raeburn 191:
192: my $xmlfile = $tempdir.'/imsmanifest.xml';
1.35 ! raeburn 193: &parse_manifest($cms,$phase,$tempdir,$xmlfile,\%toc,$includedres,
! 194: $includeditems,$items,$resources,$resinfo,$hrefs,\@seq);
! 195: return 'ok' ;
! 196: }
! 197:
! 198: sub parse_manifest {
! 199: my ($cms,$phase,$tempdir,$xmlfile,$toc,$includedres,$includeditems,$items,
! 200: $resources,$resinfo,$hrefs,$seq) = @_;
! 201: my @state = ();
! 202: my $itm = '';
! 203: my %contents = ();
! 204: my $identifier = '';
! 205: my @allidentifiers = ();
! 206: my $lastitem;
1.1 raeburn 207: my $p = HTML::Parser->new
208: (
209: xml_mode => 1,
210: start_h =>
211: [sub {
212: my ($tagname, $attr) = @_;
213: push @state, $tagname;
1.17 raeburn 214: my $start = @state - 3;
1.35 ! raeburn 215: if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $$toc{$cms}) ) {
1.17 raeburn 216: if ($state[-1] eq 'item') {
1.14 raeburn 217: $itm = $attr->{identifier};
1.16 raeburn 218: if ($$includeditems{$itm} || $phase ne 'build') {
1.14 raeburn 219: %{$$items{$itm}} = ();
220: $$items{$itm}{contentscount} = 0;
1.16 raeburn 221: @{$$items{$itm}{contents}} = ();
1.35 ! raeburn 222: if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' || $cms eq 'webctvista4') {
1.14 raeburn 223: $$items{$itm}{resnum} = $attr->{identifierref};
224: if ($cms eq 'bb5') {
225: $$items{$itm}{title} = $attr->{title};
226: }
227: } elsif ($cms eq 'angel') {
228: if ($attr->{identifierref} =~ m/^res(.+)$/) {
229: $$items{$itm}{resnum} = $1;
230: }
1.10 raeburn 231: }
1.14 raeburn 232: unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) {
233: %{$$resources{$$items{$itm}{resnum}}} = ();
1.1 raeburn 234: }
1.14 raeburn 235: $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
1.35 ! raeburn 236: if ($start > @{$seq}) {
1.14 raeburn 237: unless ($lastitem eq '') {
1.35 ! raeburn 238: push @{$seq}, $lastitem;
! 239: unless ( defined($contents{$$seq[-1]}) ) {
! 240: @{$contents{$$seq[-1]}} = ();
1.14 raeburn 241: }
1.35 ! raeburn 242: push @{$contents{$$seq[-1]}},$itm;
! 243: $$items{$itm}{parentseq} = $$seq[-1];
1.14 raeburn 244: }
1.35 ! raeburn 245: } elsif ($start < @{$seq}) {
! 246: my $diff = @{$seq} - $start;
1.14 raeburn 247: while ($diff > 0) {
1.35 ! raeburn 248: pop @{$seq};
1.14 raeburn 249: $diff --;
250: }
1.35 ! raeburn 251: if (@{$seq}) {
! 252: push @{$contents{$$seq[-1]}}, $itm;
1.1 raeburn 253: }
1.14 raeburn 254: } else {
1.35 ! raeburn 255: push @{$contents{$$seq[-1]}}, $itm;
1.1 raeburn 256: }
1.14 raeburn 257: my $path;
1.35 ! raeburn 258: if (@{$seq} > 1) {
! 259: $path = join(',',@{$seq});
! 260: } elsif (@{$seq} > 0) {
! 261: $path = $$seq[0];
1.1 raeburn 262: }
1.14 raeburn 263: $$items{$itm}{filepath} = $path;
264: if ($cms eq 'bb5' || $cms eq 'bb6') {
265: if ($$items{$itm}{filepath} eq 'Top') {
266: $$items{$itm}{resnum} = $itm;
267: $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document';
268: $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
269: $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true';
270: }
1.2 raeburn 271: }
1.35 ! raeburn 272: $$items{$$seq[-1]}{contentscount} ++;
! 273: $$resources{$$items{$itm}{resnum}}{seqref} = $seq;
1.14 raeburn 274: $lastitem = $itm;
1.2 raeburn 275: }
1.1 raeburn 276: }
1.34 raeburn 277: if ($cms eq 'webctce4') {
1.17 raeburn 278: if (($state[-1] eq "webct:properties") && (@state > 4)) {
1.16 raeburn 279: $$items{$itm}{properties} = $attr->{identifierref};
280: }
281: }
1.1 raeburn 282: } elsif ("@state" eq "manifest resources resource" ) {
283: $identifier = $attr->{identifier};
1.35 ! raeburn 284: push(@allidentifiers,$identifier);
1.14 raeburn 285: if ($$includedres{$identifier} || $phase ne 'build') {
1.16 raeburn 286: if ($cms eq 'bb5' || $cms eq 'bb6') {
1.14 raeburn 287: $$resources{$identifier}{file} = $attr->{file};
288: $$resources{$identifier}{type} = $attr->{type};
1.34 raeburn 289: } elsif ($cms eq 'webctce4') {
1.16 raeburn 290: $$resources{$identifier}{type} = $attr->{type};
291: $$resources{$identifier}{file} = $attr->{href};
1.35 ! raeburn 292: } elsif ($cms eq 'webctvista4') {
! 293: $$resources{$identifier}{type} = $attr->{type};
! 294: $$resources{$identifier}{'webct:coType'} = $attr->{'webct:coType'};
1.14 raeburn 295: } elsif ($cms eq 'angel') {
296: $identifier = substr($identifier,3);
297: if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
298: $$resources{$identifier}{file} = $1;
299: }
1.11 raeburn 300: }
1.14 raeburn 301: @{$$hrefs{$identifier}} = ();
1.1 raeburn 302: }
303: } elsif ("@state" eq "manifest resources resource file") {
1.14 raeburn 304: if ($$includedres{$identifier} || $phase ne 'build') {
1.35 ! raeburn 305: if ($cms eq 'webctvista4') {
! 306: $$resources{$identifier}{file} = $attr->{href};
! 307: }
! 308: if ($cms eq 'bb5' || $cms eq 'bb6' ||
! 309: $cms eq 'webctce4' || $cms eq 'webctvista4') {
1.14 raeburn 310: push @{$$hrefs{$identifier}},$attr->{href};
1.35 ! raeburn 311:
! 312: if ($$resources{$identifier}{type} eq
! 313: 'webct.manifest') {
! 314: my $manifestfile = $tempdir.'/'.$attr->{href};
! 315: my $currseqref = [];
! 316: if ($itm) {
! 317: $currseqref =
! 318: $$resources{$$items{$itm}{resnum}}{seqref};
! 319: }
! 320: &parse_manifest($cms,$phase,$tempdir,$manifestfile,
! 321: $toc,$includedres,$includeditems,
! 322: $items,$resources,$resinfo,
! 323: $hrefs,$currseqref);
! 324: }
1.14 raeburn 325: } elsif ($cms eq 'angel') {
326: if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
327: push @{$$hrefs{$identifier}},$1;
328: } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
329: $$resources{$identifier}{type} = $1;
330: }
1.35 ! raeburn 331: }
! 332: }
! 333: } elsif ("@state" eq "manifest webct:ContentObject") {
! 334: foreach my $ident (@allidentifiers) {
! 335: if ($$resources{$ident}{type} eq 'ims_qtiasiv1p2') {
! 336: $$resources{$ident}{type} = $attr->{'webct:coType'};
1.11 raeburn 337: }
1.1 raeburn 338: }
339: }
340: }, "tagname, attr"],
341: text_h =>
342: [sub {
343: my ($text) = @_;
1.15 raeburn 344: if ("@state" eq "manifest metadata lom general title langstring") {
345: $$items{'Top'}{title} = $text;
346: }
1.35 ! raeburn 347: if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $$toc{$cms} && $state[-1] eq "title") {
1.14 raeburn 348: if ($$includeditems{$itm} || $phase ne 'build') {
1.35 ! raeburn 349: if ($cms eq 'angel' || $cms eq 'bb6' || $cms eq 'webctvista4') {
1.14 raeburn 350: $$items{$itm}{title} = $text;
351: }
1.34 raeburn 352: if ($cms eq 'webctce4') {
1.15 raeburn 353: $$items{$itm}{title} = $text;
354: $$items{$itm}{title} =~ s/(<[^>]*>)//g;
355: }
1.4 raeburn 356: }
357: }
1.1 raeburn 358: }, "dtext"],
359: end_h =>
360: [sub {
361: my ($tagname) = @_;
362: pop @state;
363: }, "tagname"],
364: );
365: $p->parse_file($xmlfile);
366: $p->eof;
367: foreach my $itm (keys %contents) {
368: @{$$items{$itm}{contents}} = @{$contents{$itm}};
369: }
370: }
371:
1.14 raeburn 372: sub get_imports {
373: my ($includeditems,$items,$resources,$importareas,$itm) = @_;
374: if (exists($$items{$itm}{resnum})) {
375: if ($$importareas{$$resources{$$items{$itm}{resnum}}{type}}) {
376: unless (exists($$includeditems{$itm})) {
377: $$includeditems{$itm} = 1;
378: }
379: }
380: }
381: if ($$items{$itm}{contentscount} > 0) {
382: foreach my $child (@{$$items{$itm}{contents}}) {
383: &get_imports($includeditems,$items,$resources,$importareas,$child);
384: }
385: }
386: }
387:
388: sub get_parents {
389: my ($includeditems,$items,$itm) = @_;
390: my @pathitems = ();
391: if ($$items{$itm}{filepath} =~ m/,/) {
392: @pathitems = split/,/,$$items{$itm}{filepath};
393: } else {
394: $pathitems[0] = $$items{$itm}{filepath};
395: }
396: foreach (@pathitems) {
397: $$includeditems{$_} = 1;
398: }
399: }
400:
1.1 raeburn 401: sub target_resources {
1.2 raeburn 402: my ($resources,$oktypes,$targets) = @_;
1.1 raeburn 403: foreach my $key (keys %{$resources}) {
404: if ( defined($$oktypes{$$resources{$key}{type}}) ) {
405: push @{$targets}, $key;
406: }
407: }
408: return;
409: }
410:
411: sub copy_resources {
1.35 ! raeburn 412: my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$destdir,$timenow,$assessmentfiles) = @_;
1.1 raeburn 413: if ($context eq 'DOCS') {
414: foreach my $key (sort keys %{$hrefs}) {
415: if (grep/^$key$/,@{$targets}) {
1.2 raeburn 416: %{$$url{$key}} = ();
1.1 raeburn 417: foreach my $file (@{$$hrefs{$key}}) {
1.2 raeburn 418: my $source = $tempdir.'/'.$key.'/'.$file;
1.35 ! raeburn 419: if ($cms eq 'webctce4' || $cms eq 'webctvista4') {
1.15 raeburn 420: $source = $tempdir.'/'.$file;
421: }
1.2 raeburn 422: my $filename = '';
1.3 raeburn 423: my $fpath = $timenow.'/resfiles/'.$key.'/';
424: if ($cms eq 'angel') {
425: if ($file eq 'pg'.$key.'.htm') {
426: next;
1.1 raeburn 427: }
428: }
1.3 raeburn 429: $file =~ s-\\-/-g;
1.15 raeburn 430: my $copyfile = $file;
1.35 ! raeburn 431: if ($cms eq 'webctce4' || $cms eq 'webctvista4') {
1.16 raeburn 432: if ($file =~ m-/my_files/(.+)$-) {
1.15 raeburn 433: $copyfile = $1;
434: }
435: }
1.35 ! raeburn 436: unless ((($cms eq 'webctce4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) || (($cms eq 'webctvista4') && (grep/^$key$/,@{$assessmentfiles}) && $file =~ /\.xml$/)) {
1.15 raeburn 437: $copyfile = $fpath.$copyfile;
438: my $fileresult;
439: if (-e $source) {
1.31 raeburn 440: $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$copyfile,$source);
1.15 raeburn 441: }
442: }
1.1 raeburn 443: }
444: }
445: }
446: } elsif ($context eq 'CSTR') {
447: if (!-e "$destdir/resfiles") {
1.2 raeburn 448: mkdir("$destdir/resfiles",0770);
1.1 raeburn 449: }
1.2 raeburn 450: foreach my $key (sort keys %{$hrefs}) {
1.14 raeburn 451: if (grep/^$key$/,@{$targets}) {
452: foreach my $file (@{$$hrefs{$key}}) {
453: $file =~ s-\\-/-g;
1.15 raeburn 454: if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6')) {
1.14 raeburn 455: if (!-e "$destdir/resfiles/$key") {
456: mkdir("$destdir/resfiles/$key",0770);
457: }
458: my $filepath = $file;
459: my $front = '';
460: while ($filepath =~ m-(\w+)/(.+)-) {
461: $front .= $1.'/';
462: $filepath = $2;
463: my $fulldir = "$destdir/resfiles/$key/$front";
464: chop($fulldir);
465: if (!-e "$fulldir") {
466: mkdir("$fulldir",0770);
467: }
468: }
469: if ($cms eq 'angel') {
470: rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
471: } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
472: rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
1.2 raeburn 473: }
1.34 raeburn 474: } elsif ($cms eq 'webctce4') {
1.16 raeburn 475: if ($file =~ m-/my_files/(.+)$-) {
1.15 raeburn 476: my $copyfile = $1;
1.16 raeburn 477: if ($copyfile =~ m-^[^/]+/[^/]+-) {
478: my @dirs = split/\//,$copyfile;
479: my $path = "$destdir/resfiles";
480: while (@dirs > 1) {
481: $path .= '/'.$dirs[0];
482: if (!-e "$path") {
483: mkdir("$path",0755);
484: }
485: shift @dirs;
486: }
487: }
488: if (-e "$tempdir/$file") {
489: rename("$tempdir/$file","$destdir/resfiles/$copyfile");
1.15 raeburn 490: }
1.17 raeburn 491: } elsif ($file !~ m-/data/(.+)$-) {
492: &Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location");
1.15 raeburn 493: }
1.2 raeburn 494: }
495: }
496: }
497: }
498: }
499: }
500:
501: sub process_resinfo {
1.15 raeburn 502: my ($cms,$context,$docroot,$destdir,$items,$resources,$targets,$boards,$announcements,$quizzes,$surveys,$pools,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles,$packages,$hrefs,$pagesfiles,$sequencesfiles,$randompicks) = @_;
1.2 raeburn 503: my $board_id = time;
504: my $board_count = 0;
1.15 raeburn 505: my $dbparse = 0;
1.2 raeburn 506: my $announce_handling = 'include';
507: my $longcrs = '';
1.35 ! raeburn 508: my %allassessments = ();
! 509: my %allquestions = ();
1.17 raeburn 510: my %qzdbsettings = ();
511: my %catinfo = ();
1.2 raeburn 512: if ($crs =~ m/^(\d)(\d)(\d)/) {
513: $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
514: }
1.14 raeburn 515: if ($context eq 'CSTR') {
516: if (!-e "$destdir/resfiles") {
517: mkdir("$destdir/resfiles",0770);
518: }
519: }
1.2 raeburn 520: if ($cms eq 'angel') {
521: my $currboard = '';
522: foreach my $key (sort keys %{$resources}) {
1.14 raeburn 523: if (grep/^$key$/,@{$targets}) {
1.2 raeburn 524: if ($$resources{$key}{type} eq "BOARD") {
525: push @{$boards}, $key;
526: $$boardnum{$$resources{$key}{revitm}} = $board_count;
527: $currboard = $key;
528: @{$$messages{$key}} = ();
529: $$timestamp[$board_count] = $board_id;
530: $board_id ++;
531: $board_count ++;
532: } elsif ($$resources{$key}{type} eq "MESSAGE") {
533: push @{$$messages{$currboard}}, $key;
534: } elsif ($$resources{$key}{type} eq "PAGE" || $$resources{$key}{type} eq "LINK") {
535: %{$$resinfo{$key}} = ();
536: &angel_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
537: } elsif ($$resources{$key}{type} eq "QUIZ") {
538: %{$$resinfo{$key}} = ();
1.3 raeburn 539: push @{$quizzes}, $key;
1.2 raeburn 540: # &angel_assessment($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
541: } elsif ($$resources{$key}{type} eq "FORM") {
542: %{$$resinfo{$key}} = ();
1.3 raeburn 543: push @{$surveys}, $key;
1.2 raeburn 544: # &angel_assessment($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
545: } elsif ($$resources{$key}{type} eq "DROPBOX") {
546: %{$$resinfo{$key}} = ();
547: }
1.14 raeburn 548: }
1.2 raeburn 549: }
1.10 raeburn 550: } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
1.2 raeburn 551: foreach my $key (sort keys %{$resources}) {
1.14 raeburn 552: if (grep/^$key$/,@{$targets}) {
1.2 raeburn 553: if ($$resources{$key}{type} eq "resource/x-bb-document") {
554: unless ($$items{$$resources{$key}{revitm}}{filepath} eq 'Top') {
1.3 raeburn 555: %{$$resinfo{$key}} = ();
1.10 raeburn 556: &process_content($cms,$key,$context,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$resrcfiles,$packages,$hrefs);
1.2 raeburn 557: }
558: } elsif ($$resources{$key}{type} eq "resource/x-bb-staffinfo") {
559: %{$$resinfo{$key}} = ();
1.33 raeburn 560: &process_staff($key,$docroot,$destdir,\%{$$resinfo{$key}},$resrcfiles);
1.2 raeburn 561: } elsif ($$resources{$key}{type} eq "resource/x-bb-externallink") {
562: %{$$resinfo{$key}} = ();
1.33 raeburn 563: &process_link($key,$docroot,$destdir,\%{$$resinfo{$key}},$resrcfiles);
1.2 raeburn 564: } elsif ($$resources{$key}{type} eq "resource/x-bb-discussionboard") {
565: %{$$resinfo{$key}} = ();
566: unless ($db_handling eq 'ignore') {
567: push @{$boards}, $key;
568: $$timestamp[$board_count] = $board_id;
569: &process_db($key,$docroot,$destdir,$board_id,$crs,$cdom,$db_handling,$uname,\%{$$resinfo{$key}},$longcrs);
570: $board_id ++;
571: $board_count ++;
572: }
1.30 raeburn 573: } elsif ($$resources{$key}{type} =~/assessment\/x\-bb\-(qti\-)?pool/) {
1.2 raeburn 574: %{$$resinfo{$key}} = ();
1.35 ! raeburn 575: &process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
1.14 raeburn 576: push @{$pools}, $key;
1.30 raeburn 577: } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?quiz/) {
1.2 raeburn 578: %{$$resinfo{$key}} = ();
1.35 ! raeburn 579: &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
1.2 raeburn 580: push @{$quizzes}, $key;
1.30 raeburn 581: } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?survey/) {
1.2 raeburn 582: %{$$resinfo{$key}} = ();
1.35 ! raeburn 583: &process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
1.2 raeburn 584: push @{$surveys}, $key;
585: } elsif ($$resources{$key}{type} eq "assessment/x-bb-group") {
586: %{$$resinfo{$key}} = ();
587: push @{$groups}, $key;
588: &process_group($key,$docroot,$destdir,\%{$$resinfo{$key}});
589: } elsif ($$resources{$key}{type} eq "resource/x-bb-user") {
590: %{$$resinfo{$key}} = ();
591: unless ($user_handling eq 'ignore') {
592: &process_user($key,$docroot,$destdir,\%{$$resinfo{$key}},$crs,$cdom,$user_handling);
593: }
594: } elsif ($$resources{$key}{type} eq "resource/x-bb-announcement") {
595: unless ($announce_handling eq 'ignore') {
596: push @{$announcements}, $key;
597: %{$$resinfo{$key}} = ();
1.3 raeburn 598: &process_announce($key,$docroot,$destdir,\%{$$resinfo{$key}},$resinfo,$seqstem,$resrcfiles);
1.2 raeburn 599: }
600: }
1.14 raeburn 601: }
1.2 raeburn 602: }
1.3 raeburn 603: if (@{$announcements}) {
604: $$items{'Top'}{'contentscount'} ++;
605: }
606: if (@{$boards}) {
607: $$items{'Top'}{'contentscount'} ++;
608: }
609: if (@{$quizzes}) {
610: $$items{'Top'}{'contentscount'} ++;
611: }
612: if (@{$surveys}) {
613: $$items{'Top'}{'contentscount'} ++;
614: }
1.14 raeburn 615: if (@{$pools}) {
616: $$items{'Top'}{'contentscount'} ++;
617: }
1.34 raeburn 618: } elsif ($cms eq 'webctce4') {
1.15 raeburn 619: foreach my $key (sort keys %{$resources}) {
620: if (grep/^$key$/,@{$targets}) {
621: if ($$resources{$key}{type} eq "webcontent") {
622: %{$$resinfo{$key}} = ();
1.16 raeburn 623: &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
1.15 raeburn 624: } elsif ($$resources{$key}{type} eq "webctquiz") {
1.35 ! raeburn 625: &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
! 626: }
! 627: }
! 628: }
! 629: } elsif ($cms eq 'webctvista4') {
! 630: foreach my $key (sort keys %{$resources}) {
! 631: if (grep/^$key$/,@{$targets}) {
! 632: %{$$resinfo{$key}} = ();
! 633: if ($$resources{$key}{type} eq 'webct.question') {
! 634: $allquestions{$key} = 1;
! 635: } elsif ($$resources{$key}{type} eq 'webct.assessment') {
! 636: $allassessments{$key} = 1;
1.15 raeburn 637: }
638: }
639: }
1.35 ! raeburn 640: if (keys(%allassessments) > 0) {
! 641: foreach my $key (sort(keys(%allassessments))) {
! 642: &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
! 643: }
! 644: } elsif (keys(%allquestions) > 0) {
! 645: my %catinfo = ();
! 646: my @allids = ();
! 647: my @allquestids = ();
! 648: my %allanswers = ();
! 649: my %allchoices = ();
! 650: my $containerdir;
! 651: my $newdir;
! 652: my $cid;
! 653: my $randompickflag = 0;
! 654: if ($context eq 'DOCS') {
! 655: $cid = $env{'request.course.id'};
! 656: }
! 657: my $destresdir = $destdir;
! 658: if ($context eq 'CSTR') {
! 659: $destresdir =~ s|/home/$uname/public_html/|/res/$udom/$uname/|;
! 660: } elsif ($context eq 'DOCS') {
! 661: $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
! 662: }
! 663: foreach my $res (sort(keys(%allquestions))) {
! 664: my $parent = $allquestions{$res};
! 665: &parse_webctvista4_question($res,$docroot,$resources,$hrefs,\%qzdbsettings,\@allquestids,\%allanswers,\%allchoices,$parent,\%catinfo);
! 666: }
! 667: &build_category_sequences($destdir,\%catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$crs,\%qzdbsettings);
! 668: &write_webct4_questions($cms,\@allquestids,$context,\%qzdbsettings,$dirname,\%allanswers,\%allchoices,$total,$cid,$cdom,$crs,$destdir,\%catinfo);
! 669: }
1.2 raeburn 670: }
1.3 raeburn 671:
1.2 raeburn 672: $$total{'board'} = $board_count;
1.3 raeburn 673: $$total{'quiz'} = @{$quizzes};
674: $$total{'surv'} = @{$surveys};
1.14 raeburn 675: $$total{'pool'} = @{$pools};
1.2 raeburn 676: }
677:
678: sub build_structure {
1.15 raeburn 679: my ($cms,$context,$destdir,$items,$resinfo,$resources,$targets,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$pools,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames,$packages,$includeditems,$randompicks) = @_;
1.2 raeburn 680: my %flag = ();
681: my %count = ();
682: my %pagecontents = ();
683: my %seqtext = ();
684: my $topnum = 0;
1.14 raeburn 685: my $topspecials = @$announcements + @$boards + @$quizzes + @$surveys + @$pools;
1.2 raeburn 686:
687: if (!-e "$destdir") {
688: mkdir("$destdir",0755);
689: }
690: if (!-e "$destdir/sequences") {
691: mkdir("$destdir/sequences",0770);
692: }
693: if (!-e "$destdir/resfiles") {
694: mkdir("$destdir/resfiles",0770);
695: }
696: if (!-e "$destdir/pages") {
697: mkdir("$destdir/pages",0770);
698: }
699: if (!-e "$destdir/problems") {
700: mkdir("$destdir/problems",0770);
701: }
702:
703: $seqtext{'Top'} = qq|<map>\n|;
704: %{$$resinfo{$$items{'Top'}{resnum}}} = (
705: isfolder => 'true',
706: );
707:
708: my $srcstem = "";
709:
710: if ($context eq 'DOCS') {
711: $srcstem = "/uploaded/$cdom/$crs/$timenow";
712: } elsif ($context eq 'CSTR') {
713: $srcstem = "/res/$udom/$uname/$newdir";
714: }
715:
716: foreach my $key (sort keys %{$items}) {
1.14 raeburn 717: if ($$includeditems{$key}) {
1.2 raeburn 718: %{$flag{$key}} = (
719: page => 0,
720: seq => 0,
721: board => 0,
722: file => 0,
723: );
724:
725: %{$count{$key}} = (
726: page => -1,
727: seq => 0,
728: board => 0,
729: file => 0,
730: );
731:
732: my $src = "";
733:
734: my $next_id = 2;
735: my $curr_id = 1;
736: my $resnum = $$items{$key}{resnum};
737: my $type = $$resources{$resnum}{type};
1.15 raeburn 738: my $contentscount = $$items{$key}{'contentscount'};
1.34 raeburn 739: if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webctce4' && $contentscount > 0)) {
1.10 raeburn 740: unless (($cms eq 'bb5') && $key eq 'Top') {
1.2 raeburn 741: $seqtext{$key} = "<map>\n";
742: }
1.15 raeburn 743: if ($contentscount == 0) {
1.14 raeburn 744: if ($key eq 'Top') {
745: unless ($topspecials) {
746: $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
747: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
748: <resource id="$next_id" src="" type="finish"></resource>\n|;
749: }
750: } else {
751: $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
1.2 raeburn 752: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
753: <resource id="$next_id" src="" type="finish"></resource>\n|;
1.14 raeburn 754: }
1.2 raeburn 755: } else {
1.16 raeburn 756: my $contcount = 0;
757: if (defined($$items{$key}{contents})) {
758: $contcount = @{$$items{$key}{contents}};
759: } else {
1.17 raeburn 760: &Apache::lonnet::logthis("IMS Import error for item: $key- contents count = $contentscount, but identity of contents not defined.");
1.16 raeburn 761: }
1.2 raeburn 762: my $contitem = $$items{$key}{contents}[0];
1.15 raeburn 763: my $contitemcount = $$items{$contitem}{contentscount};
1.16 raeburn 764: my ($res,$itm,$type,$file);
1.15 raeburn 765: if (exists($$items{$contitem}{resnum})) {
766: $res = $$items{$contitem}{resnum};
767: $itm = $$resources{$res}{revitm};
768: $type = $$resources{$res}{type};
1.16 raeburn 769: $file = $$resources{$res}{file};
1.15 raeburn 770: }
1.2 raeburn 771: my $title = $$items{$contitem}{title};
1.10 raeburn 772: my $packageflag = 0;
773: if (grep/^$res$/,@{$packages}) {
774: $packageflag = 1;
775: }
1.18 raeburn 776: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
1.2 raeburn 777: unless ($flag{$key}{page} == 1) {
1.18 raeburn 778: if ($$randompicks{$contitem}) {
779: $seqtext{$key} .= qq|
780: <param to="$curr_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>\n|;
781: }
1.5 raeburn 782: $seqtext{$key} .= qq|<resource id="$curr_id" src="$src" title="$title" type="start"|;
1.2 raeburn 783: unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) {
784: $flag{$key}{page} = 1;
785: }
786: if ($key eq 'Top') {
787: push @{$topurls}, $src;
788: push @{$topnames}, $title;
789: }
790: }
791: if ($contcount == 1) {
792: $seqtext{$key} .= qq|></resource>
1.14 raeburn 793: <link from="$curr_id" to="$next_id" index="$curr_id"></link>|;
794: if ($key eq 'Top') {
795: unless ($topspecials) {
796: $seqtext{$key} .= qq|
797: <resource id="$next_id" src="" type="finish"></resource>\n|;
798: }
799: } else {
800: $seqtext{$key} .= qq|
1.2 raeburn 801: <resource id="$next_id" src="" type="finish"></resource>\n|;
1.14 raeburn 802: }
1.2 raeburn 803: } else {
804: if ($contcount > 2 ) {
805: for (my $i=1; $i<$contcount-1; $i++) {
806: my $contitem = $$items{$key}{contents}[$i];
1.15 raeburn 807: my $contitemcount = $$items{$contitem}{contentscount};
1.2 raeburn 808: my $res = $$items{$contitem}{resnum};
809: my $type = $$resources{$res}{type};
1.16 raeburn 810: my $file = $$resources{$res}{file};
1.10 raeburn 811: my $title = $$items{$contitem}{title};
812: my $packageflag = 0;
813: if (grep/^$res$/,@{$packages}) {
814: $packageflag = 1;
815: }
1.18 raeburn 816: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
1.2 raeburn 817: unless ($flag{$key}{page} == 1) {
818: $seqtext{$key} .= qq|></resource>
1.18 raeburn 819: <link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|;
820: if ($$randompicks{$contitem}) {
821: $seqtext{$key} .= qq|
822: <param to="$next_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>|;
823: }
824: $seqtext{$key} .= qq|
1.2 raeburn 825: <resource id="$next_id" src="$src" title="$title"|;
826: $curr_id ++;
827: $next_id ++;
828: unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) {
829: $flag{$key}{page} = 1;
830: }
831: if ($key eq 'Top') {
832: push @{$topurls}, $src;
833: push @{$topnames}, $title;
834: }
835: }
836: }
837: }
838: my $contitem = $$items{$key}{contents}[-1];
1.15 raeburn 839: my $contitemcount = $$items{$contitem}{contentscount};
1.2 raeburn 840: my $res = $$items{$contitem}{resnum};
841: my $type = $$resources{$res}{type};
1.16 raeburn 842: my $file = $$resources{$res}{file};
1.2 raeburn 843: my $title = $$items{$contitem}{title};
1.10 raeburn 844: my $packageflag = 0;
845: if (grep/^$res$/,@{$packages}) {
846: $packageflag = 1;
847: }
1.18 raeburn 848: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
1.15 raeburn 849:
1.2 raeburn 850: if ($flag{$key}{page}) {
851: if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) {
852: $seqtext{$key} .= qq|></resource>
853: <link from="$curr_id" index="$curr_id" to="$next_id">
854: <resource id ="$next_id" src="" |;
855: }
856: } else {
857: $seqtext{$key} .= qq|></resource>
1.18 raeburn 858: <link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|;
859: if ($$randompicks{$contitem}) {
860: $seqtext{$key} .= qq|
861: <param to="$next_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>\n|;
862: }
863: $seqtext{$key} .= qq|
1.2 raeburn 864: <resource id="$next_id" src="$src" title="$title" |;
865: if ($key eq 'Top') {
866: push @{$topurls}, $src;
867: push @{$topnames}, $title;
868: }
869: }
870: if ($contcount == $$items{$key}{contentscount}) {
871: $seqtext{$key} .= qq|type="finish"></resource>\n|;
872: } else {
873: $curr_id ++;
874: $next_id ++;
875: $seqtext{$key} .= qq|></resource>
1.8 raeburn 876: <link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|;
1.2 raeburn 877: }
878: }
879: }
1.10 raeburn 880: unless (($cms eq 'bb5') && $key eq 'Top') {
1.2 raeburn 881: $seqtext{$key} .= "</map>\n";
882: open(LOCFILE,">$destdir/sequences/$key.sequence");
883: print LOCFILE $seqtext{$key};
884: close(LOCFILE);
885: push @{$seqfiles}, "$key.sequence";
886: }
887: $count{$key}{page} ++;
888: $$total{page} += $count{$key}{page};
889: }
890: $$total{seq} += $count{$key}{seq};
1.14 raeburn 891: }
1.2 raeburn 892: }
893: $topnum += ($count{'Top'}{page} + $count{'Top'}{seq});
894:
1.10 raeburn 895: if ($cms eq 'bb5' || $cms eq 'bb6') {
1.2 raeburn 896: if (@{$announcements} > 0) {
897: &process_specials($context,'announcements',$announcements,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
898: }
899: if (@{$boards} > 0) {
900: &process_specials($context,'boards',$boards,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
901: }
902: if (@{$quizzes} > 0) {
903: &process_specials($context,'quizzes',$quizzes,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
904: }
905: if (@{$surveys} > 0) {
906: &process_specials($context,'surveys',$surveys,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
907: }
1.14 raeburn 908: if (@{$pools} > 0) {
909: &process_specials($context,'pools',$pools,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
910: }
1.2 raeburn 911: $seqtext{'Top'} .= "</map>\n";
912: open(TOPFILE,">$destdir/sequences/Top.sequence");
913: print TOPFILE $seqtext{'Top'};
914: close(TOPFILE);
915: push @{$seqfiles}, 'Top.sequence';
916: }
917:
918: my $filestem;
919: if ($context eq 'DOCS') {
1.6 raeburn 920: $filestem = "/uploaded/$cdom/$crs/$timenow";
1.2 raeburn 921: } elsif ($context eq 'CSTR') {
922: $filestem = "/res/$udom/$uname/$newdir";
923: }
924:
925: foreach my $key (sort keys %pagecontents) {
926: for (my $i=0; $i<@{$pagecontents{$key}}; $i++) {
927: my $filename = $destdir.'/pages/'.$key.'_'.$i.'.page';
1.10 raeburn 928: my $resource = "$filestem/resfiles/$$items{$pagecontents{$key}[$i][0]}{resnum}.html";
929: my $res = $$items{$pagecontents{$key}[$i][0]}{resnum};
930: my $resource = $filestem.'/resfiles/'.$res.'.html';
931: if (grep/^$res$/,@{$packages}) {
932: $resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point
933: }
1.2 raeburn 934: open(PAGEFILE,">$filename");
935: print PAGEFILE qq|<map>
1.10 raeburn 936: <resource src="$resource" id="1" type="start" title="$$items{$pagecontents{$key}[$i][0]}{title}"></resource>
1.2 raeburn 937: <link to="2" index="1" from="1">\n|;
938: if (@{$pagecontents{$key}[$i]} == 1) {
1.3 raeburn 939: print PAGEFILE qq|<resource src="" id="2" type="finish"></resource>\n|;
1.2 raeburn 940: } elsif (@{$pagecontents{$key}[$i]} == 2) {
1.10 raeburn 941: my $res = $$items{$pagecontents{$key}[$i][1]}{resnum};
942: my $resource = $filestem.'/resfiles/'.$res.'.html';
943: if (grep/^$res$/,@{$packages}) {
944: $resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point
945: }
946: print PAGEFILE qq|<resource src="$resource" id="2" type="finish" title="$$items{$pagecontents{$key}[$i][1]}{title}"></resource>\n|;
1.2 raeburn 947: } else {
948: for (my $j=1; $j<@{$pagecontents{$key}[$i]}-1; $j++) {
949: my $curr_id = $j+1;
950: my $next_id = $j+2;
1.10 raeburn 951: my $res = $$items{$pagecontents{$key}[$i][$j]}{resnum};
952: my $resource = $filestem.'/resfiles/'.$res.'.html';
953: if (grep/^$res$/,@{$packages}) {
954: $resource = $filestem.'/resfiles/'.$res.'./index.html'; # entry_point
955: }
1.2 raeburn 956: print PAGEFILE qq|<resource src="$resource" id="$curr_id" title="$$items{$pagecontents{$key}[$i][$j]}{title}"></resource>
957: <link to="$next_id" index="$curr_id" from="$curr_id">\n|;
958: }
959: my $final_id = @{$pagecontents{$key}[$i]};
1.10 raeburn 960: my $res = $$items{$pagecontents{$key}[$i][-1]}{resnum};
961: my $resource = $filestem.'/resfiles/'.$res.'.html';
962: if (grep/^$res$/,@{$packages}) {
963: $resource = $filestem.'/resfiles/'.$res.'./index.html'; # entry_point
964: }
965: print PAGEFILE qq|<resource src="$resource" id="$final_id" type="finish" title="$$items{$pagecontents{$key}[$i][-1]}{title}"></resource>\n|;
1.2 raeburn 966: }
967: print PAGEFILE "</map>";
968: close(PAGEFILE);
969: push @{$pagesfiles}, $key.'_'.$i.'.page';
970: }
971: }
972: }
973:
974: sub make_structure {
1.18 raeburn 975: my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick) = @_;
1.2 raeburn 976: my $src ='';
1.34 raeburn 977: if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webctce4' && $contitemcount > 0)) {
1.2 raeburn 978: $src = $srcstem.'/sequences/'.$contitem.'.sequence';
979: $$flag{$key}{page} = 0;
980: $$flag{$key}{seq} = 1;
981: $$count{$key}{seq} ++;
1.34 raeburn 982: } elsif ($cms eq 'webctce4' && $randompick) {
1.18 raeburn 983: $src = $srcstem.'/sequences/'.$res.'.sequence';
984: $$flag{$key}{page} = 0;
985: $$flag{$key}{seq} = 1;
986: $$count{$key}{seq} ++;
1.2 raeburn 987: } elsif ($cms eq 'angel' && $type eq 'BOARD') {
988: $src = '/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$$boardnum{$res}].'/bulletinboard';
989: $$flag{$key}{page} = 0;
990: $$flag{$key}{board} = 1;
991: $$count{$key}{board} ++;
992: } elsif ($cms eq 'angel' && $type eq "FILE") {
993: foreach my $file (@{$$hrefs{$res}}) {
994: unless ($file eq 'pg'.$res.'.htm') {
995: $src = $srcstem.'/resfiles/'.$res.'/'.$file;
996: }
997: }
998: $$flag{$key}{page} = 0;
999: $$flag{$key}{file} = 1;
1000: } elsif ($cms eq 'angel' && (($type eq "PAGE") || ($type eq "LINK")) ) {
1001: if ($$flag{$key}{page}) {
1.3 raeburn 1002: if ($$count{$key}{page} == -1) {
1.17 raeburn 1003: &Apache::lonnet::logthis("IMS Angel import error in array index for page: value = -1, resource is $key, type is $type.");
1.2 raeburn 1004: } else {
1005: push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem;
1006: }
1007: } else {
1008: $$count{$key}{page} ++;
1009: $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page';
1010: @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem");
1011: $$flag{$key}{seq} = 0;
1012: }
1.10 raeburn 1013: } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
1.2 raeburn 1014: if ($$flag{$key}{page}) {
1015: push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem;
1016: } else {
1.10 raeburn 1017: if ($contcount == 1) {
1018: if ($packageflag) {
1019: $src = $srcstem.'/resfiles/'.$res.'/index.html'; # Needs to be entry point
1020: } else {
1021: $src = $srcstem.'/resfiles/'.$res.'.html';
1022: }
1023: } else {
1024: $$count{$key}{page} ++;
1025: $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page';
1026: @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem");
1027: }
1.2 raeburn 1028: $$flag{$key}{seq} = 0;
1029: }
1.34 raeburn 1030: } elsif ($cms eq 'webctce4') {
1.17 raeburn 1031: if ($type eq 'webctquiz') {
1032: $src = $srcstem.'/pages/'.$res.'.page';
1.18 raeburn 1033: $$count{$key}{page} ++;
1034: $$flag{$key}{seq} = 0;
1.17 raeburn 1035: } else {
1.16 raeburn 1036: if (grep/^$file$/,@{$$hrefs{$res}}) {
1.15 raeburn 1037: my $filename;
1038: if ($file =~ m-/([^/]+)$-) {
1039: $filename = $1;
1040: }
1.16 raeburn 1041: $src = $srcstem.'/resfiles/'.$res.'/'.$filename;
1042: } else {
1043: foreach my $file (@{$$hrefs{$res}}) {
1044: my $filename;
1045: if ($file =~ m-/([^/]+)$-) {
1046: $filename = $1;
1047: }
1048: $src = $srcstem.'/resfiles/'.$res.'/'.$filename;
1049: }
1.15 raeburn 1050: }
1051: $$flag{$key}{page} = 0;
1052: $$flag{$key}{file} = 1;
1053: }
1.2 raeburn 1054: }
1055: return $src;
1056: }
1057:
1058:
1059: # ---------------------------------------------------------------- Process Blackboard specials - announcements, bulletin boards, quizzes and surveys
1060: sub process_specials {
1061: my ($context,$type,$specials,$topnum,$contentscount,$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,$seqtext,$pagesfiles,$seqfiles,$topurls,$topnames) = @_;
1062: my $src = '';
1063: my $specialsrc = '';
1064: my $nextnum = 0;
1065: my $seqstem = '';
1066: if ($context eq 'CSTR') {
1.3 raeburn 1067: $seqstem = "/res/$udom/$uname/$newdir";
1.2 raeburn 1068: } elsif ($context eq 'DOCS') {
1069: $seqstem = '/uploaded/'.$cdom.'/'.$crs.'/'.$timenow;
1070: }
1071: my %seqnames = (
1072: boards => 'bulletinboards',
1073: quizzes => 'quizzes',
1074: surveys => 'surveys',
1075: announcements => 'announcements',
1.14 raeburn 1076: pools => 'pools'
1.2 raeburn 1077: );
1078: my %seqtitles = (
1079: boards => 'Course Bulletin Boards',
1080: quizzes => 'Course Quizzes',
1081: surveys => 'Course Surveys',
1082: announcements => 'Course Announcements',
1.14 raeburn 1083: pools => 'Course Question Pools'
1.2 raeburn 1084: );
1085: $$topnum ++;
1086:
1087: if ($type eq 'announcements') {
1088: $src = "$seqstem/pages/$seqnames{$type}.page";
1089: } else {
1090: $src = "$seqstem/sequences/$seqnames{$type}.sequence";
1091: }
1092:
1093: push @{$topurls}, $src;
1094: push @{$topnames}, $seqtitles{$type};
1095:
1096: $$seqtext .= qq|<resource id="$$topnum" src="$src" title="$seqtitles{$type}"|;
1097: $nextnum = $$topnum +1;
1098: if ($$topnum == 1) {
1099: $$seqtext .= qq| type="start"></resource>
1100: <link from="$$topnum" to="$nextnum" index="$$topnum"></link>\n|;
1101: if ($$topnum == $contentscount) {
1102: $$seqtext .= qq|<resource id="$nextnum" src="" type="finish"></resource>\n|;
1103: }
1104: } else {
1105: if ($$topnum == $contentscount) {
1106: $$seqtext .= qq| type="finish"></resource>\n|;
1107: } else {
1108: $$seqtext .= qq|></resource>
1109: <link from="$$topnum" to="$nextnum" index="$$topnum"></link>\n|;
1110: }
1111: }
1112:
1113: if ($type eq "announcements") {
1114: push @{$pagesfiles}, "$seqnames{$type}.page";
1115: open(ITEM,">$destdir/pages/$seqnames{$type}.page");
1116: } else {
1117: push @{$seqfiles}, "$seqnames{$type}.sequence";
1118: open(ITEM,">$destdir/sequences/$seqnames{$type}.sequence");
1119: }
1120:
1121: if ($type eq 'boards') {
1122: $specialsrc = "/adm/$udom/$uname/$$timestamp[0]/bulletinboard";
1123: } elsif ($type eq 'announcements') {
1124: $specialsrc = "$seqstem/resfiles/$$specials[0].html";
1.14 raeburn 1125: } elsif ($type eq 'pools') {
1126: $specialsrc = "$seqstem/sequences/$$specials[0].sequence";
1.2 raeburn 1127: } else {
1128: $specialsrc = "$seqstem/pages/$$specials[0].page";
1129: }
1130: print ITEM qq|<map>
1131: <resource id="1" src="$specialsrc" title="$$resinfo{$$specials[0]}{title}" type="start"></resource>
1132: <link from="1" to="2" index="1"></link>|;
1133: if (@{$specials} == 1) {
1134: print ITEM qq|
1135: <resource id="2" src="" type="finish"></resource>\n|;
1136: } else {
1137: for (my $i=1; $i<@{$specials}; $i++) {
1138: my $curr = $i+1;
1139: my $next = $i+2;
1140: if ($type eq 'boards') {
1141: $specialsrc = "/adm/$udom/$uname/$$timestamp[$i]/bulletinboard";
1142: } elsif ($type eq 'announcements') {
1143: $specialsrc = "$seqstem/resfiles/$$specials[$i].html";
1144: } else {
1145: $specialsrc = "$seqstem/pages/$$specials[$i].page";
1146: }
1147: print ITEM qq|<resource id="$curr" src="$specialsrc" title="$$resinfo{$$specials[$i]}{title}"|;
1148: if (@{$specials} == $i+1) {
1149: print ITEM qq| type="finish"></resource>\n|;
1150: } else {
1151: print ITEM qq|></resource>
1152: <link from="$curr" to="$next" index="$next">\n|;
1153: }
1154: }
1155: }
1156: print ITEM qq|</map>|;
1157: close(ITEM);
1158: }
1159:
1160: # ---------------------------------------------------------------- Process Blackboard users
1161: sub process_user {
1162: my ($res,$docroot,$destdir,$settings,$user_crs,$user_cdom,$user_handling) = @_;
1163: my $xmlfile = $docroot.'/'.$res.".dat";
1164: my $filecount = 0;
1165: my @state;
1166: my $userid = '';
1167: my $linknum = 0;
1168:
1169: my $p = HTML::Parser->new
1170: (
1171: xml_mode => 1,
1172: start_h =>
1173: [sub {
1174: my ($tagname, $attr) = @_;
1175: push @state, $tagname;
1.7 raeburn 1176: if ("@state" eq "USERS USER") {
1.2 raeburn 1177: $userid = $attr->{value};
1178: %{$$settings{$userid}} = ();
1179: @{$$settings{$userid}{links}} = ();
1.7 raeburn 1180: } elsif ("@state" eq "USERS USER LOGINID") {
1.2 raeburn 1181: $$settings{$userid}{loginid} = $attr->{value};
1.7 raeburn 1182: } elsif ("@state" eq "USERS USER PASSPHRASE") {
1.2 raeburn 1183: $$settings{$userid}{passphrase} = $attr->{value};
1184: } elsif ("@state" eq "USERS USER STUDENTID" ) {
1185: $$settings{$userid}{studentid} = $attr->{value};
1186: } elsif ("@state" eq "USERS USER NAMES FAMILY" ) {
1187: $$settings{$userid}{family} = $attr->{value};
1188: } elsif ("@state" eq "USERS USER NAMES GIVEN" ) {
1189: $$settings{$userid}{given} = $attr->{value};
1190: } elsif ("@state" eq "USERS USER ADDRESSES BUSINESS DATA EMAIL") {
1191: $$settings{$userid}{email} = $attr->{value};
1192: } elsif ("@state" eq "USERS USER USER_ROLE") {
1193: $$settings{$userid}{user_role} = $attr->{value};
1194: } elsif ("@state" eq "USERS USER FLAGS ISAVAILABLE") {
1195: $$settings{$userid}{isavailable} = $attr->{value};
1196: } elsif ("@state" eq "USERS USER PERSONALPAGE FILELIST IMAGE") {
1197: $$settings{$userid}{image} = $attr->{value};
1198: } elsif ( ($state[-2] eq "LINKLIST") && ($state[-1] eq "LINK") ) {
1199: %{$$settings{$userid}{links}[$linknum]} = ();
1200: $$settings{$userid}{links}[$linknum]{url} = $attr->{value};
1201: $linknum ++;
1202: }
1203: }, "tagname, attr"],
1204: text_h =>
1205: [sub {
1206: my ($text) = @_;
1207: if ("@state" eq "USERS USER PERSONALPAGE TITLE") {
1208: $$settings{$userid}{title} = $text;
1209: } elsif ("@state" eq "USERS USER PERSONALPAGE DESCRIPTION") {
1210: $$settings{$userid}{description} = $text;
1211: } elsif (($state[-2] eq "LINK") && ($state[-1] eq "TITLE")) {
1212: $$settings{$userid}{links}[$linknum]{title} = $text;
1213: } elsif (($state[-3] eq "LINK") && ($state[-2] eq "DESCRIPTION") && ($state[-1] eq "TEXT")) {
1214: $$settings{$userid}{links}[$linknum]{text} = $text;
1215: }
1216: }, "dtext"],
1217: end_h =>
1218: [sub {
1219: my ($tagname) = @_;
1.7 raeburn 1220: if ("@state" eq "USERS USER") {
1.2 raeburn 1221: $linknum = 0;
1222: }
1223: pop @state;
1224: }, "tagname"],
1225: );
1226: $p->unbroken_text(1);
1227: $p->parse_file($xmlfile);
1228: $p->eof;
1229:
1230: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
1231: my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$user_cdom."_".$user_crs."_";
1232:
1233: foreach my $user_id (keys %{$settings}) {
1234: if ($$settings{$user_id}{user_role} eq "s") {
1235:
1236: } elsif ($user_handling eq 'enrollall') {
1237:
1238: }
1239: }
1240: }
1241:
1242: # ---------------------------------------------------------------- Process Blackboard groups
1243: sub process_group {
1244: my ($res,$docroot,$destdir,$settings) = @_;
1245: my $xmlfile = $docroot.'/'.$res.".dat";
1246: my $filecount = 0;
1247: my @state;
1248: my $grp;
1249:
1250: my $p = HTML::Parser->new
1251: (
1252: xml_mode => 1,
1253: start_h =>
1254: [sub {
1255: my ($tagname, $attr) = @_;
1256: push @state, $tagname;
1.7 raeburn 1257: if ("@state" eq "GROUPS GROUP") {
1.2 raeburn 1258: $grp = $attr->{id};
1259: }
1.7 raeburn 1260: if ("@state" eq "GROUPS GROUP TITLE") {
1.2 raeburn 1261: $$settings{$grp}{title} = $attr->{value};
1.7 raeburn 1262: } elsif ("@state" eq "GROUPS GROUP FLAGS ISAVAILABLE") {
1.2 raeburn 1263: $$settings{$grp}{isavailable} = $attr->{value};
1.7 raeburn 1264: } elsif ("@state" eq "GROUPS GROUP FLAGS HASCHATROOM") {
1.2 raeburn 1265: $$settings{$grp}{chat} = $attr->{value};
1266: } elsif ("@state" eq "GROUPS GROUP FLAGS HASDISCUSSIONBOARD") {
1267: $$settings{$grp}{discussion} = $attr->{value};
1268: } elsif ("@state" eq "GROUPS GROUP FLAGS HASTRANSFERAREA") {
1269: $$settings{$grp}{transfer} = $attr->{value};
1270: } elsif ("@state" eq "GROUPS GROUP FLAGS ISPUBLIC") {
1271: $$settings{$grp}{public} = $attr->{value};
1272: }
1273: }, "tagname, attr"],
1274: text_h =>
1275: [sub {
1276: my ($text) = @_;
1277: if ("@state" eq "GROUPS DESCRIPTION") {
1278: $$settings{$grp}{description} = $text;
1279: # print "Staff text is $text\n";
1280: }
1281: }, "dtext"],
1282: end_h =>
1283: [sub {
1284: my ($tagname) = @_;
1285: pop @state;
1286: }, "tagname"],
1287: );
1288: $p->unbroken_text(1);
1289: $p->parse_file($xmlfile);
1290: $p->eof;
1291: }
1292:
1293: # ---------------------------------------------------------------- Process Blackboard Staff
1294: sub process_staff {
1.33 raeburn 1295: my ($res,$docroot,$destdir,$settings,$resrcfiles) = @_;
1.2 raeburn 1296: my $xmlfile = $docroot.'/'.$res.".dat";
1297: my $filecount = 0;
1298: my @state;
1299: %{$$settings{name}} = ();
1.33 raeburn 1300: %{$$settings{office}} = ();
1.2 raeburn 1301:
1302: my $p = HTML::Parser->new
1303: (
1304: xml_mode => 1,
1305: start_h =>
1306: [sub {
1307: my ($tagname, $attr) = @_;
1308: push @state, $tagname;
1.7 raeburn 1309: if ("@state" eq "STAFFINFO TITLE") {
1.2 raeburn 1310: $$settings{title} = $attr->{value};
1.7 raeburn 1311: } elsif ("@state" eq "STAFFINFO BIOGRAPHY TEXTCOLOR") {
1.2 raeburn 1312: $$settings{textcolor} = $attr->{value};
1.7 raeburn 1313: } elsif ("@state" eq "STAFFINFO BIOGRAPHY FLAGS ISHTML") {
1.2 raeburn 1314: $$settings{ishtml} = $attr->{value};
1315: } elsif ("@state" eq "STAFFINFO FLAGS ISAVAILABLE" ) {
1316: $$settings{isavailable} = $attr->{value};
1317: } elsif ("@state" eq "STAFFINFO FLAGS ISFOLDER" ) {
1318: $$settings{isfolder} = $attr->{value};
1319: } elsif ("@state" eq "STAFFINFO POSITION" ) {
1320: $$settings{position} = $attr->{value};
1321: } elsif ("@state" eq "STAFFINFO HOMEPAGE" ) {
1322: $$settings{homepage} = $attr->{value};
1323: } elsif ("@state" eq "STAFFINFO IMAGE") {
1324: $$settings{image} = $attr->{value};
1325: }
1326: }, "tagname, attr"],
1327: text_h =>
1328: [sub {
1329: my ($text) = @_;
1330: if ("@state" eq "STAFFINFO BIOGRAPHY TEXT") {
1331: $$settings{text} = $text;
1332: # print "Staff text is $text\n";
1333: } elsif ("@state" eq "STAFFINFO CONTACT PHONE") {
1334: $$settings{phone} = $text;
1335: } elsif ("@state" eq "STAFFINFO CONTACT EMAIL") {
1336: $$settings{email} = $text;
1337: } elsif ("@state" eq "STAFFINFO CONTACT NAME FORMALTITLE") {
1338: $$settings{name}{formaltitle} = $text;
1339: } elsif ("@state" eq "STAFFINFO CONTACT NAME FAMILY") {
1340: $$settings{name}{family} = $text;
1341: } elsif ("@state" eq "STAFFINFO CONTACT NAME GIVEN") {
1342: $$settings{name}{given} = $text;
1343: } elsif ("@state" eq "STAFFINFO CONTACT OFFICE HOURS") {
1344: $$settings{office}{hours} = $text;
1345: } elsif ("@state" eq "STAFFINFO CONTACT OFFICE ADDRESS") {
1346: $$settings{office}{address} = $text;
1347: }
1348: }, "dtext"],
1349: end_h =>
1350: [sub {
1351: my ($tagname) = @_;
1352: pop @state;
1353: }, "tagname"],
1354: );
1355: $p->unbroken_text(1);
1356: $p->parse_file($xmlfile);
1357: $p->eof;
1358:
1359: my $fontcol = '';
1360: if (defined($$settings{textcolor})) {
1361: $fontcol = qq|color="$$settings{textcolor}"|;
1362: }
1363: if (defined($$settings{text})) {
1364: if ($$settings{ishtml} eq "true") {
1365: $$settings{text} = &HTML::Entities::decode($$settings{text});
1366: }
1367: }
1368: my $staffentry = qq|
1369: <table border="0" cellpadding="0" cellspacing="0" width="100%">
1370: <tr>
1371: <td colspan="2"><hr /><font face="arial,helv" size="3"><b>$$settings{name}{formaltitle} $$settings{name}{given} $$settings{name}{family}</b></font>
1372: </td>
1373: </tr>
1374: <tr>
1375: <td valign="top">
1376: <table width="100% border="0" cols="2" cellpadding="0" cellspacing="0">|;
1377: if ( defined($$settings{email}) && $$settings{email} ne '') {
1378: $staffentry .= qq|
1379: <tr>
1380: <td width="100" valign="top">
1381: <font face="arial" size="2"><b>Email:</b></font>
1382: </td>
1383: <td>
1384: <font face="arial" size="2"><a href="mailto:$$settings{email}">$$settings{email}</a></font>
1385: </td>
1386: </tr>
1387: |;
1388: }
1389: if (defined($$settings{phone}) && $$settings{phone} ne '') {
1390: $staffentry .= qq|
1391: <tr>
1392: <td width="100" valign="top">
1393: <font face="arial" size="2"><b>Phone:</b></font>
1394: </td>
1395: <td>
1396: <font face="arial" size="2">$$settings{phone}</font>
1397: </td>
1398: </tr>
1399: |;
1400: }
1401: if (defined($$settings{office}{address}) && $$settings{office}{address} ne '') {
1402: $staffentry .= qq|
1403: <tr>
1404: <td width="100" valign="top">
1405: <font face="arial" size="2"><b>Address:</b></font>
1406: </td>
1407: <td>
1408: <font face="arial" size="2">$$settings{office}{address}</font>
1409: </td>
1410: </tr>
1411: |;
1412: }
1413: if (defined($$settings{office}{hours}) && $$settings{office}{hours} ne '') {
1414: $staffentry .= qq|
1415: <tr>
1416: <td width="100" valign="top">
1417: <font face="arial" size="2"><b>Office Hours:</b></font>
1418: </td>
1419: <td>
1420: <font face=arial size=2>$$settings{office}{hours}</font>
1421: </td>
1422: </tr>
1423: |;
1424: }
1425: if ( defined($$settings{homepage}) && $$settings{homepage} ne '') {
1426: $staffentry .= qq|
1427: <tr>
1428: <td width="100" valign="top">
1429: <font face="arial" size="2"><b>Personal Link:</b></font>
1430: </td>
1431: <td>
1432: <font face="arial" size="2"><a href="$$settings{homepage}">$$settings{homepage}</a></font>
1433: </td>
1434: </tr>
1435: |;
1436: }
1437: if (defined($$settings{text}) && $$settings{text} ne '') {
1438: $staffentry .= qq|
1439: <tr>
1440: <td colspan="2">
1441: <font face="arial" size="2" $fontcol><b>Other Information:</b><br/>$$settings{text}</font>
1442: </td>
1443: </tr>
1444: |;
1445: }
1446: $staffentry .= qq|
1447: </table>
1448: </td>
1449: <td align="right" valign="top">
1450: |;
1451: if ( defined($$settings{image}) ) {
1452: $staffentry .= qq|
1.33 raeburn 1453: <img src="$res/$$settings{image}">
1.2 raeburn 1454: |;
1455: }
1456: $staffentry .= qq|
1457: </td>
1458: </tr>
1459: </table>
1460: |;
1461: open(FILE,">$destdir/resfiles/$res.html");
1462: push @{$resrcfiles}, "$res.html";
1463: print FILE qq|<html>
1464: <head>
1465: <title>$$settings{title}</title>
1466: </head>
1467: <body bgcolor='#ffffff'>
1468: $staffentry
1469: </body>
1470: </html>|;
1471: close(FILE);
1472: }
1473:
1474: # ---------------------------------------------------------------- Process Blackboard Links
1475: sub process_link {
1.33 raeburn 1476: my ($res,$docroot,$destdir,$settings,$resrcfiles) = @_;
1.2 raeburn 1477: my $xmlfile = $docroot.'/'.$res.".dat";
1478: my @state = ();
1479: my $p = HTML::Parser->new
1480: (
1481: xml_mode => 1,
1482: start_h =>
1483: [sub {
1484: my ($tagname, $attr) = @_;
1485: push @state, $tagname;
1.7 raeburn 1486: if ("@state" eq "EXTERNALLINK TITLE") {
1.2 raeburn 1487: $$settings{title} = $attr->{value};
1.7 raeburn 1488: } elsif ("@state" eq "EXTERNALLINK TEXTCOLOR") {
1.2 raeburn 1489: $$settings{textcolor} = $attr->{value};
1.7 raeburn 1490: } elsif ("@state" eq "EXTERNALLINK DESCRIPTION FLAGS ISHTML") {
1.15 raeburn 1491: $$settings{ishtml} = $attr->{value};
1.2 raeburn 1492: } elsif ("@state" eq "EXTERNALLINK FLAGS ISAVAILABLE" ) {
1493: $$settings{isavailable} = $attr->{value};
1494: } elsif ("@state" eq "EXTERNALLINK FLAGS LAUNCHINNEWWINDOW" ) {
1495: $$settings{newwindow} = $attr->{value};
1496: } elsif ("@state" eq "EXTERNALLINK FLAGS ISFOLDER" ) {
1497: $$settings{isfolder} = $attr->{value};
1498: } elsif ("@state" eq "EXTERNALLINK POSITION" ) {
1499: $$settings{position} = $attr->{value};
1500: } elsif ("@state" eq "EXTERNALLINK URL" ) {
1.7 raeburn 1501: $$settings{url} = $attr->{value};
1.2 raeburn 1502: }
1503: }, "tagname, attr"],
1504: text_h =>
1505: [sub {
1506: my ($text) = @_;
1507: if ("@state" eq "EXTERNALLINK DESCRIPTION TEXT") {
1508: $$settings{text} = $text;
1509: }
1510: }, "dtext"],
1511: end_h =>
1512: [sub {
1513: my ($tagname) = @_;
1514: pop @state;
1515: }, "tagname"],
1516: );
1517: $p->unbroken_text(1);
1518: $p->parse_file($xmlfile);
1519: $p->eof;
1520:
1521: my $linktag = '';
1522: my $fontcol = '';
1523: if (defined($$settings{textcolor})) {
1524: $fontcol = qq|<font color="$$settings{textcolor}">|;
1525: }
1526: if (defined($$settings{text})) {
1527: if ($$settings{ishtml} eq "true") {
1528: $$settings{text} = &HTML::Entities::decode($$settings{text});
1529: }
1530: }
1531:
1532: if (defined($$settings{url}) ) {
1533: $linktag = qq|<a href="$$settings{url}"|;
1534: if ($$settings{newwindow} eq "true") {
1535: $linktag .= qq| target="launch"|;
1536: }
1537: $linktag .= qq|>$$settings{title}</a>|;
1538: }
1539:
1540: open(FILE,">$destdir/resfiles/$res.html");
1541: push @{$resrcfiles}, "$res.html";
1542: print FILE qq|<html>
1543: <head>
1544: <title>$$settings{title}</title>
1545: </head>
1546: <body bgcolor='#ffffff'>
1547: $fontcol
1548: $linktag
1549: $$settings{text}
1550: |;
1551: if (defined($$settings{textcolor})) {
1552: print FILE qq|</font>|;
1553: }
1554: print FILE qq|
1555: </body>
1556: </html>|;
1557: close(FILE);
1558: }
1559:
1560: # ---------------------------------------------------------------- Process Blackboard Discussion Boards
1561: sub process_db {
1562: my ($res,$docroot,$destdir,$timestamp,$crs,$cdom,$handling,$uname,$settings,$longcrs) = @_;
1563: my $xmlfile = $docroot.'/'.$res.".dat";
1564: my @state = ();
1565: my @allmsgs = ();
1566: my %msgidx = ();
1567: my %threads; # all threads, keyed by message ID
1568: my $msg_id; # the current message ID
1569: my %message; # the current message being accumulated for $msg_id
1570:
1571: my $p = HTML::Parser->new
1572: (
1573: xml_mode => 1,
1574: start_h =>
1575: [sub {
1576: my ($tagname, $attr) = @_;
1577: push @state, $tagname;
1578: my $depth = 0;
1579: my @seq = ();
1580: if ("@state" eq "FORUM TITLE") {
1581: $$settings{title} = $attr->{value};
1582: } elsif ("@state" eq "FORUM DESCRIPTION TEXTCOLOR") {
1583: $$settings{textcolor} = $attr->{value};
1584: } elsif ("@state" eq "FORUM DESCRIPTION FLAGS ISHTML") {
1585: $$settings{ishtml} = $attr->{value};
1586: } elsif ("@state" eq "FORUM DESCRIPTION FLAGS ISNEWLINELITERAL") {
1587: $$settings{newline} = $attr->{value};
1588: } elsif ("@state" eq "FORUM POSITION" ) {
1589: $$settings{position} = $attr->{value};
1590: } elsif ("@state" eq "FORUM FLAGS ISREADONLY") {
1591: $$settings{isreadonly} = $attr->{value};
1592: } elsif ("@state" eq "FORUM FLAGS ISAVAILABLE" ) {
1593: $$settings{isavailable} = $attr->{value};
1594: } elsif ("@state" eq "FORUM FLAGS ALLOWANONYMOUSPOSTINGS" ) {
1595: $$settings{allowanon} = $attr->{value};
1596: } elsif ( ($state[0] eq "FORUM") && ($state[1] eq "MESSAGETHREADS") && ($state[2] eq "MSG") ) {
1597: if ($state[-1] eq "MSG") {
1598: unless ($msg_id eq '') {
1599: push @{$threads{$msg_id}}, { %message };
1600: $depth = @state - 3;
1601: if ($depth > @seq) {
1602: push @seq, $msg_id;
1603: }
1604: }
1605: if ($depth < @seq) {
1606: pop @seq;
1607: }
1608: $msg_id = $attr->{id};
1609: push @allmsgs, $msg_id;
1610: $msgidx{$msg_id} = @allmsgs;
1611: %message = ();
1612: $message{depth} = $depth;
1613: if ($depth > 0) {
1614: $message{parent} = $seq[-1];
1615: } else {
1616: $message{parent} = "None";
1617: }
1618: } elsif ($state[-1] eq "TITLE") {
1619: $message{title} = $attr->{value};
1620: } elsif ( ( $state[-3] eq "MESSAGETEXT" ) && ( $state[-2] eq "FLAGS" ) && ( $state[-1] eq "ISHTML" ) ) {
1621: $message{ishtml} = $attr->{value};
1622: } elsif ( ( $state[-3] eq "MESSAGETEXT" ) && ( $state[-2] eq "FLAGS" ) && ( $state[-1] eq "ISNEWLINELITERAL" ) ) {
1623: $message{newline} = $attr->{value};
1624: } elsif ( ( $state[-2] eq "DATES" ) && ( $state[-1] eq "CREATED" ) ) {
1625: $message{created} = $attr->{value};
1626: } elsif ( $state[@state-2] eq "FLAGS") {
1627: if ($state[@state-1] eq "ISANONYMOUS") {
1628: $message{isanonymous} = $attr->{value};
1629: }
1630: } elsif ( $state[-2] eq "USER" ) {
1631: if ($state[-1] eq "USERID") {
1632: $message{userid} = $attr->{value};
1633: } elsif ($state[@state-1] eq "USERNAME") {
1634: $message{username} = $attr->{value};
1635: } elsif ($state[@state-1] eq "EMAIL") {
1636: $message{email} = $attr->{value};
1637: }
1638: } elsif ( ($state[-2] eq "FILELIST") && ($state[-1] eq "IMAGE") ) {
1639: $message{attachment} = $attr->{value};
1640: }
1641: }
1642: }, "tagname, attr"],
1643: text_h =>
1644: [sub {
1645: my ($text) = @_;
1646: if ("@state" eq "FORUM DESCRIPTION TEXT") {
1647: $$settings{text} = $text;
1648: } elsif ( ($state[0] eq "FORUM") && ($state[1] eq "MESSAGETHREADS") && ($state[2] eq "MSG") ) {
1649: if ( ($state[-2] eq "MESSAGETEXT") && ($state[-1] eq "TEXT") ){
1650: $message{text} = $text;
1651: }
1652: }
1653: }, "dtext"],
1654: end_h =>
1655: [sub {
1656: my ($tagname) = @_;
1657: if ( $state[-1] eq "MESSAGETHREADS" ) {
1658: push @{$threads{$msg_id}}, { %message };
1659: }
1660: pop @state;
1661: }, "tagname"],
1662: );
1663: $p->unbroken_text(1);
1664: $p->parse_file($xmlfile);
1665: $p->eof;
1666:
1667: if (defined($$settings{text})) {
1668: if ($$settings{ishtml} eq "false") {
1669: if ($$settings{isnewline} eq "true") {
1670: $$settings{text} =~ s#\n#<br/>#g;
1671: }
1672: } else {
1673: $$settings{text} = &HTML::Entities::decode($$settings{text});
1674: }
1675: if (defined($$settings{fontcolor}) ) {
1676: $$settings{text} = "<font color=\"".$$settings{textcolor}."\">".$$settings{text}."</font>";
1677: }
1678: }
1679: my $boardname = 'bulletinpage_'.$timestamp;
1680: my %boardinfo = (
1681: 'aaa_title' => $$settings{title},
1682: 'bbb_content' => $$settings{text},
1683: 'ccc_webreferences' => '',
1684: 'uploaded.lastmodified' => time,
1685: );
1686:
1687: my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$cdom,$crs);
1688: if ($handling eq 'importall') {
1689: foreach my $msg_id (@allmsgs) {
1690: foreach my $message ( @{$threads{$msg_id}} ) {
1691: my %contrib = (
1692: 'sendername' => $$message{userid},
1693: 'senderdomain' => $cdom,
1694: 'screenname' => '',
1695: 'plainname' => $$message{username},
1696: );
1697: unless ($$message{parent} eq 'None') {
1698: $contrib{replyto} = $msgidx{$$message{parent}};
1699: }
1700: if (defined($$message{isanonymous}) ) {
1701: if ($$message{isanonymous} eq 'true') {
1702: $contrib{'anonymous'} = 'true';
1703: }
1704: }
1705: if ( defined($$message{attachment}) ) {
1706: my $url = $$message{attachment};
1707: my $oldurl = $url;
1708: my $newurl = $url;
1709: unless ($url eq '') {
1710: $newurl =~ s/\//_/g;
1711: unless ($longcrs eq '') {
1712: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles") {
1713: mkdir("/home/httpd/lonUsers/$cdom/$longcrs/userfiles",0755);
1714: }
1715: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl") {
1716: system("cp $destdir/resfiles/$res/$$message{attachment} /home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl");
1717: }
1718: $contrib{attachmenturl} = '/uploaded/'.$cdom.'/'.$crs.'/'.$newurl;
1719: }
1720: }
1721: }
1722: if (defined($$message{title}) ) {
1723: $contrib{'message'} = $$message{title};
1724: }
1725: if (defined($$message{text})) {
1726: if ($$message{ishtml} eq "false") {
1727: if ($$message{isnewline} eq "true") {
1728: $$message{text} =~ s#\n#<br/>#g;
1729: }
1730: } else {
1731: $$message{text} = &HTML::Entities::decode($$message{text});
1732: }
1733: $contrib{'message'} .= '<br /><br />'.$$message{text};
1734: my $symb = 'bulletin___'.$timestamp.'___adm/wrapper/adm/'.$cdom.'/'.$uname.'/'.$timestamp.'/bulletinboard';
1735: my $postresult = &addposting($symb,\%contrib,$cdom,$crs);
1736: }
1737: }
1738: }
1739: }
1740: }
1741:
1742: # ---------------------------------------------------------------- Add Posting to Bulletin Board
1743: sub addposting {
1744: my ($symb,$contrib,$cdom,$crs)=@_;
1745: my $status='';
1746: if (($symb) && ($$contrib{message})) {
1747: my $crsdom = $cdom.'_'.$crs;
1748: &Apache::lonnet::store($contrib,$symb,$crsdom,$cdom,$crs);
1749: my %storenewentry=($symb => time);
1750: &Apache::lonnet::put('discussiontimes',\%storenewentry,$cdom,$crs);
1751: }
1752: my %record=&Apache::lonnet::restore('_discussion');
1753: my ($temp)=keys %record;
1754: unless ($temp=~/^error\:/) {
1755: my %newrecord=();
1756: $newrecord{'resource'}=$symb;
1757: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1758: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1759: $status = 'ok';
1760: } else {
1761: $status.='Failed.';
1762: }
1763: return $status;
1764: }
1.15 raeburn 1765:
1766: sub parse_bb5_assessment {
1767: my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_;
1.2 raeburn 1768: my $xmlfile = $docroot.'/'.$res.".dat";
1769: my @state = ();
1770: my $id; # the current question ID
1771: my $answer_id; # the current answer ID
1772: my %toptag = ( pool => 'POOL',
1773: quiz => 'ASSESSMENT',
1774: survey => 'ASSESSMENT'
1775: );
1776:
1777: my $p = HTML::Parser->new
1778: (
1779: xml_mode => 1,
1780: start_h =>
1781: [sub {
1782: my ($tagname, $attr) = @_;
1783: push @state, $tagname;
1784: my $depth = 0;
1785: my @seq = ();
1786: my $class;
1787: my $state_str = join(" ",@state);
1788: if ($container eq "pool") {
1789: if ("@state" eq "POOL TITLE") {
1790: $$settings{title} = $attr->{value};
1791: }
1792: } else {
1793: if ("@state" eq "ASSESSMENT TITLE") {
1794: $$settings{title} = $attr->{value};
1795: } elsif ("@state" eq "ASSESSMENT FLAG" ) {
1796: $$settings{isnewline} = $attr->{value};
1797: } elsif ("@state" eq "ASSESSMENT FLAGS ISAVAILABLE") {
1798: $$settings{isavailable} = $attr->{value};
1799: } elsif ("@state" eq "ASSESSMENT FLAGS ISANONYMOUS" ) {
1800: $$settings{isanonymous} = $attr->{id};
1801: } elsif ("@state" eq "ASSESSMENT FLAGS GIVE FEEDBACK" ) {
1802: $$settings{feedback} = $attr->{id};
1803: } elsif ("@state" eq "ASSESSMENT FLAGS SHOWCORRECT" ) {
1804: $$settings{showcorrect} = $attr->{id};
1805: } elsif ("@state" eq "ASSESSMENT FLAGS SHOWRESULTS" ) {
1806: $$settings{showresults} = $attr->{id};
1807: } elsif ("@state" eq "ASSESSMENT FLAGS ALLOWMULTIPLE" ) {
1808: $$settings{allowmultiple} = $attr->{id};
1809: } elsif ("@state" eq "ASSESSMENT ASSESSMENTTYPE" ) {
1810: $$settings{type} = $attr->{id};
1811: }
1812: }
1813: if ("@state" eq "$toptag{$container} QUESTIONLIST QUESTION") {
1814: $id = $attr->{id};
1.15 raeburn 1815: push @{$allids}, $id;
1.2 raeburn 1816: %{$$settings{$id}} = ();
1.15 raeburn 1817: @{$$allanswers{$id}} = ();
1.2 raeburn 1818: $$settings{$id}{class} = $attr->{class};
1819: unless ($container eq "pool") {
1820: $$settings{$id}{points} = $attr->{points};
1821: }
1822: @{$$settings{$id}{correctanswer}} = ();
1823: } elsif ( ($state[0] eq $toptag{$container}) && ($state[-1] =~ m/^QUESTION_(\w+)$/) ) {
1824: $id = $attr->{id};
1825: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "FLAGS") ) {
1826: if ($state[4] eq "ISHTML") {
1.20 raeburn 1827: $$settings{$id}{ishtml} = $attr->{value};
1.2 raeburn 1828: } elsif ($state[4] eq "ISNEWLINELITERAL") {
1829: $$settings{$id}{newline} = $attr->{value};
1830: }
1831: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "IMAGE") ) {
1832: $$settings{$id}{image} = $attr->{value};
1833: $$settings{$id}{style} = $attr->{style};
1834: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "URL") ) {
1835: $$settings{$id}{url} = $attr->{value};
1836: $$settings{$id}{name} = $attr->{name};
1837: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[-1] eq "ANSWER") ) {
1838: $answer_id = $attr->{id};
1.15 raeburn 1839: push @{$$allanswers{$id}},$answer_id;
1.2 raeburn 1840: %{$$settings{$id}{$answer_id}} = ();
1841: $$settings{$id}{$answer_id}{position} = $attr->{position};
1842: if ($$settings{$id}{class} eq 'QUESTION_MATCH') {
1843: $$settings{$id}{$answer_id}{placement} = $attr->{placement};
1844: $$settings{$id}{$answer_id}{type} = 'answer';
1845: }
1846: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[-1] eq "CHOICE") ) {
1847: $answer_id = $attr->{id};
1.15 raeburn 1848: push @{$$allchoices{$id}},$answer_id;
1.2 raeburn 1849: %{$$settings{$id}{$answer_id}} = ();
1850: $$settings{$id}{$answer_id}{position} = $attr->{position};
1851: $$settings{$id}{$answer_id}{placement} = $attr->{placement};
1852: $$settings{$id}{$answer_id}{type} = 'choice';
1853: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "ANSWER") ) {
1854: if ($state[3] eq "IMAGE") {
1855: $$settings{$id}{$answer_id}{image} = $attr->{value};
1856: $$settings{$id}{$answer_id}{style} = $attr->{style};
1857: } elsif ($state[3] eq "URL") {
1858: $$settings{$id}{$answer_id}{url} = $attr->{value};
1859: }
1860: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "CHOICE") ) {
1861: if ($state[3] eq "IMAGE") {
1862: $$settings{$id}{$answer_id}{image} = $attr->{value};
1863: $$settings{$id}{$answer_id}{style} = $attr->{style};
1864: } elsif ($state[3] eq "URL") {
1865: $$settings{$id}{$answer_id}{url} = $attr->{value};
1866: }
1867: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[3] eq "CORRECTANSWER") ) {
1868: my $corr_answer = $attr->{answer_id};
1869: push @{$$settings{$id}{correctanswer}}, $corr_answer;
1870: my $type = $1;
1871: if ($type eq 'TRUEFALSE') {
1872: $$settings{$id}{$corr_answer}{answer_position} = $attr->{position};
1873: } elsif ($type eq 'ORDER') {
1874: $$settings{$id}{$corr_answer}{order} = $attr->{order};
1875: } elsif ($type eq 'MATCH') {
1876: $$settings{$id}{$corr_answer}{choice_id} = $attr->{choice_id};
1877: }
1878: }
1879: }, "tagname, attr"],
1880: text_h =>
1881: [sub {
1882: my ($text) = @_;
1.16 raeburn 1883: $text =~ s/^\s+//g;
1884: $text =~ s/\s+$//g;
1.2 raeburn 1885: unless ($container eq "pool") {
1886: if ("@state" eq "ASSESSMENT DESCRIPTION TEXT") {
1887: $$settings{description} = $text;
1888: } elsif ("@state" eq "ASSESSMENT INSTRUCTIONS ") {
1889: $$settings{instructions}{text} = $text;
1890: }
1891: }
1.16 raeburn 1892: if ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[-1] eq "TEXT") ) {
1893: unless ($text eq '') {
1894: $$settings{$id}{text} = $text;
1895: }
1896: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "ANSWER") && ($state[-1] eq "TEXT") ) {
1897: unless ($text eq '') {
1898: $$settings{$id}{$answer_id}{text} = $text;
1899: }
1900: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "CHOICE") && ($state[-1] eq "TEXT") ) {
1901: unless ($text eq '') {
1902: $$settings{$id}{$answer_id}{text} = $text;
1903: }
1904: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[-1] eq "FEEDBACK_WHEN_CORRECT") ) {
1905: unless ($text eq '') {
1906: $$settings{$id}{feedback_corr} = $text;
1907: }
1908: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[-1] eq "FEEDBACK_WHEN_INCORRECT") ) {
1909: unless ($text eq '') {
1910: $$settings{$id}{feedback_incorr} = $text;
1911: }
1.2 raeburn 1912: }
1913: }, "dtext"],
1914: end_h =>
1915: [sub {
1916: my ($tagname) = @_;
1917: pop @state;
1918: }, "tagname"],
1919: );
1920: $p->unbroken_text(1);
1.16 raeburn 1921: $p->marked_sections(1);
1.2 raeburn 1922: $p->parse_file($xmlfile);
1923: $p->eof;
1.15 raeburn 1924: }
1925:
1926: sub parse_bb6_assessment {
1.30 raeburn 1927: my ($res,$docroot,$container,$settings,$allids) = @_;
1.28 raeburn 1928: my $xmlfile = $docroot.'/'.$res.".dat";
1929: my @state = ();
1930: my $id; # the current question ID
1.29 raeburn 1931: my $response; # the current response ID
1.30 raeburn 1932: my $foil; # the current foil ID
1933: my $numchoice; # the current right match choice;
1934: my $labelcount; # the current count of choices for a matching item.
1.28 raeburn 1935: my $curr_shuffle;
1.30 raeburn 1936: my $curr_class; # the current question type
1.29 raeburn 1937: my $curr_matchitem;
1.30 raeburn 1938: my $curr_block_type; # the current block type
1939: my $curr_flow; # the current flow class attribute
1940: my $curr_flow_mat; # the current flow_mat class attribute
1941: my $curr_feedback_type; # the current feedback type
1942: my $numorder; # counter for ordering type questions
1943:
1944: my $itemfrag = "questestinterop assessment section item";
1945: my $presfrag = "$itemfrag presentation flow flow";
1946: my $blockflow = 'flow';
1947: my $responselid;
1948: my $instructionfrag = "questestinterop assessment presentation_material flow_mat material";
1949: my $feedbackfrag = "$itemfrag itemfeedback";
1950: my $feedback_tag = '';
1951: my $responselid;
1.28 raeburn 1952: my $p = HTML::Parser->new
1953: (
1954: xml_mode => 1,
1955: start_h =>
1956: [sub {
1957: my ($tagname, $attr) = @_;
1958: push @state, $tagname;
1959: if ("@state" eq "questestinterop assessment") {
1960: $$settings{title} = $attr->{title};
1961: }
1.29 raeburn 1962: if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") {
1.30 raeburn 1963: $$settings{description}{texttype} = $attr->{type};
1.29 raeburn 1964: }
1.30 raeburn 1965: if ("@state" eq $presfrag) {
1966: if ($attr->{class} eq 'QUESTION_BLOCK') {
1967: $curr_block_type = 'question';
1968: } elsif ($attr->{class} eq 'RESPONSE_BLOCK') {
1.29 raeburn 1969: $curr_block_type = 'response';
1.30 raeburn 1970: if ($curr_class eq 'Matching') {
1971: $responselid = 'flow response_lid';
1972: } else {
1973: $responselid = 'response_lid';
1974: }
1975: } elsif (($attr->{class} eq 'RIGHT_MATCH_BLOCK')) {
1976: $numchoice = 0;
1.29 raeburn 1977: $curr_block_type = 'rightmatch';
1.30 raeburn 1978: }
1.29 raeburn 1979: }
1.30 raeburn 1980: if ("@state" eq "$presfrag flow") {
1981: if (($curr_block_type =~ /^rightmatch/) && ($attr->{class} eq 'Block')) {
1982: $curr_block_type = 'rightmatch'.$numchoice;
1983: $numchoice ++;
1.29 raeburn 1984: }
1.28 raeburn 1985: }
1.30 raeburn 1986: if ($state[-1] eq 'flow') {
1987: $curr_flow = $attr->{class};
1.28 raeburn 1988: }
1.30 raeburn 1989: if ($state[-1] eq 'flow_mat') {
1990: $curr_flow_mat = $attr->{class};
1991: }
1992: if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") {
1.29 raeburn 1993: $$settings{$id}{$curr_block_type}{texttype} = $attr->{texttype};
1.28 raeburn 1994: }
1.30 raeburn 1995: if ("@state" eq "$presfrag $blockflow material matapplication") {
1.29 raeburn 1996: $$settings{$id}{$curr_block_type}{image} = $attr->{uri};
1997: $$settings{$id}{$curr_block_type}{style} = $attr->{embedded};
1998: $$settings{$id}{$curr_block_type}{label} = $attr->{label};
1.28 raeburn 1999: }
1.30 raeburn 2000: if ("@state" eq "$presfrag $blockflow material mattext") {
1.29 raeburn 2001: $$settings{$id}{$curr_block_type}{link} = $attr->{uri};
1.28 raeburn 2002: }
1.30 raeburn 2003: if ("@state" eq "$presfrag $responselid") {
2004: $response = $attr->{ident};
2005: $labelcount = 0;
1.29 raeburn 2006: if ($curr_class eq 'Matching') {
1.30 raeburn 2007: push(@{$$settings{$id}{answers}},$response);
1.29 raeburn 2008: %{$$settings{$id}{$response}} = ();
2009: foreach my $key (keys(%{$$settings{$id}{$curr_block_type}})) {
2010: $$settings{$id}{$response}{$key} = $$settings{$id}{$curr_block_type}{$key};
2011: }
2012: %{$$settings{$id}{$curr_block_type}} = ();
2013: }
2014: }
1.30 raeburn 2015: if ("@state" eq "$presfrag $responselid render_choice") {
2016: $curr_shuffle = $attr->{shuffle};
2017: }
2018: if ("@state" eq "$presfrag $responselid render_choice flow_label response_label") {
2019: $foil = $attr->{ident};
2020: %{$$settings{$id}{$foil}} = ();
2021: $$settings{$id}{$foil}{randomize} = $curr_shuffle;
2022: unless ($curr_class eq 'Essay'){
2023: if ($curr_class eq 'Matching') {
2024: push(@{$$settings{$id}{$response}{items}},$foil);
2025: $$settings{$id}{$foil}{order} = $labelcount;
2026: $labelcount ++;
2027: } else {
2028: push(@{$$settings{$id}{answers}},$foil);
2029: @{$$settings{$id}{correctanswer}} = ();
2030: }
2031: }
2032: }
2033: if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material matapplication") {
2034: $$settings{$id}{$foil}{filetype} = $attr->{embedded};
2035: $$settings{$id}{$foil}{label} = $attr->{label};
2036: $$settings{$id}{$foil}{uri} = $attr->{uri};
2037: }
2038: if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") {
2039: $$settings{$id}{$foil}{link} = $attr->{uri};
1.29 raeburn 2040: }
1.30 raeburn 2041: if ("@state" eq "questestinterop assessment section item resprocessing") {
2042: if ($curr_class eq 'Matching') {
2043: $$settings{$id}{allchoices} = $numchoice;
2044: }
1.29 raeburn 2045: }
1.30 raeburn 2046: if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") {
1.29 raeburn 2047: if ($curr_class eq 'Matching') {
2048: $curr_matchitem = $attr->{respident};
1.28 raeburn 2049: }
2050: }
1.30 raeburn 2051: if ("@state" eq $feedbackfrag) {
1.28 raeburn 2052: $curr_feedback_type = $attr->{ident};
1.30 raeburn 2053: $feedback_tag = "";
2054: }
2055: if ("@state" eq "$feedbackfrag solution") {
2056: $curr_feedback_type = 'solution';
2057: $feedback_tag = "solution solutionmaterial";
1.28 raeburn 2058: }
1.30 raeburn 2059: if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material matapplication") {
1.28 raeburn 2060: $$settings{$id}{$curr_feedback_type.'feedback'}{filetype} = $attr->{'embedded'};
2061: $$settings{$id}{$curr_feedback_type.'feedback'}{label} = $attr->{label};
1.30 raeburn 2062: $$settings{$id}{$curr_feedback_type.'feedback'}{uri} = $attr->{uri};
1.28 raeburn 2063: }
1.30 raeburn 2064: if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") {
1.28 raeburn 2065: $$settings{$id}{$curr_feedback_type.'feedback'}{link} = $attr->{uri};
2066: }
2067: }, "tagname, attr"],
2068: text_h =>
2069: [sub {
2070: my ($text) = @_;
2071: $text =~ s/^\s+//g;
2072: $text =~ s/\s+$//g;
2073: if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") {
1.30 raeburn 2074: $$settings{description}{text} = $text;
2075: }
2076: if ("@state" eq "questestinterop assessment rubric flow_mat material mattext") {
2077: $$settings{description}{text} = $text;
2078: }
2079: if ("@state" eq "$instructionfrag mat_extension mat_formattedtext") {
2080: $$settings{instructions}{text} = $text;
2081: }
2082: if ("@state" eq "$instructionfrag mattext") {
1.28 raeburn 2083: $$settings{instructions}{text} = $text;
2084: }
2085: if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_asi_object_id") {
2086: $id = $text;
2087: push @{$allids}, $id;
2088: %{$$settings{$id}} = ();
1.30 raeburn 2089: @{$$settings{$id}{answers}} = ();
1.29 raeburn 2090: %{$$settings{$id}{question}} = ();
1.28 raeburn 2091: %{$$settings{$id}{correctfeedback}} = ();
2092: %{$$settings{$id}{incorrectfeedback}} = ();
1.29 raeburn 2093: %{$$settings{$id}{solutionfeedback}} = ();
1.28 raeburn 2094: }
2095: if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_questiontype") {
2096: $$settings{$id}{class} = $text;
1.29 raeburn 2097: $curr_class = $text;
1.30 raeburn 2098: if ($curr_class eq 'Matching') {
2099: $blockflow = 'flow flow';
2100: } else {
2101: $blockflow = 'flow';
2102: }
1.28 raeburn 2103: }
1.30 raeburn 2104: if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") {
1.29 raeburn 2105: $$settings{$id}{$curr_block_type}{text} = $text;
1.28 raeburn 2106: }
1.30 raeburn 2107: if ("@state" eq "$presfrag $blockflow material mattext") {
2108: if ($curr_flow eq 'LINK_BLOCK') {
2109: $$settings{$id}{$curr_block_type}{linkname} = $text;
2110: } elsif ($curr_flow eq 'FORMATTED_TEXT_BLOCK') {
2111: $$settings{$id}{$curr_block_type}{text} = $text;
2112: }
1.28 raeburn 2113: }
1.30 raeburn 2114: if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mat_extension mat_formattedtext") {
2115: $$settings{$id}{$foil}{text} = $text;
2116: }
2117: if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") {
2118: if ($curr_flow_mat eq 'LINK_BLOCK') {
2119: $$settings{$id}{$foil}{linkname} = $text;
2120: } else {
2121: $$settings{$id}{$foil}{text} = $text;
2122: }
1.28 raeburn 2123: }
1.30 raeburn 2124: if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") {
2125: if ($curr_class eq 'Matching') {
1.29 raeburn 2126: $$settings{$id}{$curr_matchitem}{correctanswer} = $text;
1.30 raeburn 2127: } else {
2128: push(@{$$settings{$id}{correctanswer}},$text);
1.28 raeburn 2129: }
2130: }
1.30 raeburn 2131: if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar") {
2132: $numorder = 0;
1.29 raeburn 2133: }
1.30 raeburn 2134: if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar and varequal") {
2135: push(@{$$settings{$id}{correctanswer}},$text);
2136: if ($curr_class eq 'Ordering') {
2137: $numorder ++;
2138: $$settings{$id}{$text}{order} = $numorder;
2139: }
2140: }
2141: if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mat_extension mat_formattedtext") {
1.28 raeburn 2142: $$settings{$id}{$curr_feedback_type.'feedback'}{text} = $text;
2143: }
1.30 raeburn 2144: if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") {
1.28 raeburn 2145: $$settings{$id}{$curr_feedback_type.'feedback'}{linkname} = $text;
2146: }
2147: }, "dtext"],
2148: end_h =>
2149: [sub {
2150: my ($tagname) = @_;
2151: pop @state;
2152: }, "tagname"],
2153: );
2154: $p->unbroken_text(1);
2155: $p->marked_sections(1);
2156: $p->parse_file($xmlfile);
2157: $p->eof;
2158: return;
1.15 raeburn 2159: }
2160:
1.35 ! raeburn 2161: sub parse_webctvista4_assessment {
! 2162: my ($res,$docroot,$href,$allids,$qzparams) = @_;
! 2163: my $xmlfile = $docroot.'/'.$href; #assessment file
! 2164: my @state = ();
! 2165: my $id; # the current question ID
! 2166: my $fieldlabel; # the current qti metadata field label
! 2167: my $outcome_id; # the current question ID for outcomes conditions
! 2168: my $pname; # the current outcomes parameter name
! 2169: my $numids = 0;
! 2170: %{$$qzparams{$res}} = ();
! 2171: %{$$qzparams{$res}{weight}} = ();
! 2172:
! 2173: my $p = HTML::Parser->new
! 2174: (
! 2175: xml_mode => 1,
! 2176: start_h =>
! 2177: [sub {
! 2178: my ($tagname, $attr) = @_;
! 2179: push @state, $tagname;
! 2180: my @seq = ();
! 2181: if ("@state" eq "questestinterop assessment section itemref") {
! 2182: $id = $attr->{linkrefid};
! 2183: push(@{$allids},$id);
! 2184: $numids ++;
! 2185: }
! 2186: if ("@state" eq "questestinterop assessment section selection_ordering order") {
! 2187: $$qzparams{$res}{order_type} = $attr->{order_type};
! 2188: }
! 2189:
! 2190: }, "tagname, attr"],
! 2191: text_h =>
! 2192: [sub {
! 2193: my ($text) = @_;
! 2194: if ("@state" eq "questestinterop assessment qtimetadata qtimetadatafield fieldlabel") {
! 2195: $fieldlabel = $text;
! 2196: }
! 2197: if ("@state" eq "questestinterop assessment qtimetadata qtimetadatafield fieldentry") {
! 2198: $$qzparams{$res}{$fieldlabel} = $text;
! 2199: }
! 2200: if ("@state" eq "questestinterop assessment section outcomes_processing objects_condition outcomes_metadata") {
! 2201: $outcome_id = $text;
! 2202: }
! 2203: if ("@state" eq "questestinterop assessment section outcomes_processing objects_condition objects_parameter") {
! 2204: if ($pname eq 'qmd_weighting') {
! 2205: $$qzparams{$res}{weight}{$outcome_id} = $text;
! 2206: }
! 2207: }
! 2208: if ("@state" eq "questestinterop assessment section selection_ordering selection selection_number") {
! 2209: $$qzparams{$res}{numpick} = $text;
! 2210: }
! 2211: }, "dtext"],
! 2212: end_h =>
! 2213: [sub {
! 2214: my ($tagname) = @_;
! 2215: pop @state;
! 2216: }, "tagname"],
! 2217: );
! 2218: $p->unbroken_text(1);
! 2219: $p->parse_file($xmlfile);
! 2220: $p->eof;
! 2221: unless(defined($$qzparams{$res}{numpick})) {
! 2222: $$qzparams{$res}{numpick} = $numids;
! 2223: }
! 2224: }
! 2225:
! 2226: sub parse_webctvista4_question {
! 2227: my ($res,$docroot,$resources,$hrefs,$settings,$allquestids,$allanswers,$allchoices,$parent,$catinfo) = @_;
! 2228: my $xmlfile = $docroot.'/'.$$resources{$res}{file};
! 2229: my %classtypes = (
! 2230: WCT_Calculated => 'numerical',
! 2231: WCT_TrueFalse => 'multiplechoice',
! 2232: WCT_ShortAnswer => 'shortanswer',
! 2233: WCT_Paragraph => 'paragraph',
! 2234: WCT_MultipleChoice => 'multiplechoice',
! 2235: WCT_Matching => 'match',
! 2236: WCT_JumbledSentence => 'jumbled',
! 2237: WCT_FillInTheBlank => 'string',
! 2238: WCT_Combination => 'combination'
! 2239: );
! 2240: my @state = ();
! 2241: my $fieldlabel;
! 2242: my %questiondata;
! 2243: my $id; # the current question ID
! 2244: my $list; # the current list ID for multiple choice questions
! 2245: my $numid; # the current answer ID for numerical questions
! 2246: my $grp; # the current group ID for matching questions
! 2247: my $label; # the current reponse label for string questions
! 2248: my $str_id; # the current string ID for string questions
! 2249: my $unitid; # the current unit ID for numerical questions
! 2250: my $answer_id; # the current answer ID
! 2251: my $fdbk; # the current feedback ID
! 2252: my $currvar; # the current variable for numerical problems
! 2253: my $fibtype; # the current fill-in-blank type for numerical or string
! 2254: my $prompt;
! 2255: my $rows;
! 2256: my $columns;
! 2257: my $maxchars;
! 2258: my %setvar = (
! 2259: varname => '',
! 2260: action => '',
! 2261: );
! 2262: my $currtexttype;
! 2263: my $jumble_item;
! 2264: my $numbox = 0;
! 2265: my %str_answers = ();
! 2266: my $currtextlabel;
! 2267: my $textlabel;
! 2268: my $currindex;
! 2269: my %varinfo = ();
! 2270: my $formula;
! 2271: my $p = HTML::Parser->new
! 2272: (
! 2273: xml_mode => 1,
! 2274: start_h =>
! 2275: [sub {
! 2276: my ($tagname, $attr) = @_;
! 2277: push @state, $tagname;
! 2278: if ("@state" eq "questestinterop item") {
! 2279: $id = $attr->{ident};
! 2280: push(@{$allquestids},$id);
! 2281: %{$$settings{$id}} = ();
! 2282: %{$varinfo{$id}} = ();
! 2283: @{$$allchoices{$id}} = ();
! 2284: @{$$settings{$id}{grps}} = ();
! 2285: @{$$settings{$id}{lists}} = ();
! 2286: @{$$settings{$id}{feedback}} = ();
! 2287: @{$$settings{$id}{str}} = ();
! 2288: %{$$settings{$id}{strings}} = ();
! 2289: @{$$settings{$id}{numids}} = ();
! 2290: %{$$allanswers{$id}} = ();
! 2291: $$settings{$id}{title} = $attr->{title};
! 2292: }
! 2293: if ("@state" eq "questestinterop item presentation flow material mat_extension webct:calculated webct:var") {
! 2294: $currvar = $attr->{'webct:name'};
! 2295: %{$varinfo{$id}{$currvar}} = ();
! 2296: $varinfo{$id}{$currvar}{min} = $attr->{'webct:min'};
! 2297: $varinfo{$id}{$currvar}{max} = $attr->{'webct:max'};
! 2298: $varinfo{$id}{$currvar}{precision} = $attr->{'webct:precision'};
! 2299: }
! 2300: if ("@state" eq "questestinterop item presentation flow response_num") {
! 2301: $numid = $attr->{ident};
! 2302: push(@{$$settings{$id}{numids}},$numid);
! 2303: %{$$settings{$id}{$numid}} = ();
! 2304: %{$$settings{$id}{$numid}{vars}} = ();
! 2305: @{$$settings{$id}{$numid}{units}} = ();
! 2306: $$settings{$id}{$numid}{rcardinality} = $attr->{rcardinality};
! 2307: $$settings{$id}{$numid}{formula} = $formula;
! 2308: foreach my $var (keys(%{$varinfo{$id}})) {
! 2309: %{$$settings{$id}{$numid}{vars}{$var}} = %{$varinfo{$id}{$var}};
! 2310: }
! 2311: }
! 2312: if ("@state" eq "questestinterop item presentation flow material mat_extension webct:variable") {
! 2313: $$settings{$id}{text} .= '['.$attr->{'webct:name'}.']';
! 2314: }
! 2315: if ("@state" eq "questestinterop item presentation flow material matimage") {
! 2316: $$settings{$id}{image} = $attr->{uri};
! 2317: }
! 2318:
! 2319: if ("@state" eq "questestinterop item presentation flow material mattext") {
! 2320: $currtexttype = lc($attr->{texttype});
! 2321: $$settings{$id}{texttype} = $currtexttype;
! 2322: if ($$settings{$id}{class} eq 'combination') {
! 2323: if (exists($attr->{label})) {
! 2324: $textlabel = $attr->{label};
! 2325: } else {
! 2326: $textlabel = '';
! 2327: }
! 2328: }
! 2329: }
! 2330: if ("@state" eq "questestinterop item presentation flow response_lid") {
! 2331: $list = $attr->{ident};
! 2332: push(@{$$settings{$id}{lists}},$list);
! 2333: %{$$settings{$id}{$list}} = ();
! 2334: @{$$allanswers{$id}{$list}} = ();
! 2335: @{$$settings{$id}{$list}{correctanswer}} = ();
! 2336: @{$$settings{$id}{$list}{jumbled}} = ();
! 2337: $$settings{$id}{$list}{rcardinality} = $attr->{rcardinality};
! 2338: }
! 2339: # Jumbled sentence
! 2340: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object") {
! 2341: $$settings{$id}{$list}{orientation} = $attr->{orientation};
! 2342: }
! 2343: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object material mattext") {
! 2344: $currtexttype = lc($attr->{texttype});
! 2345: $$settings{$id}{$list}{texttype} = $currtexttype;
! 2346: }
! 2347: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object response_label") {
! 2348: $jumble_item = $attr->{ident};
! 2349: }
! 2350: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object response_label material mattext") {
! 2351: $currtexttype = lc($attr->{texttype});
! 2352: $$settings{$id}{$list}{$jumble_item}{texttype} = $currtexttype;
! 2353: }
! 2354: if ("@state" eq "questestinterop item resprocessing respcondition conditionvar and varequal") { # Jumbled
! 2355: $currindex = $attr->{index};
! 2356: }
! 2357: if ("@state" eq "questestinterop item presentation flow response_lid render_choice") {
! 2358: $$settings{$id}{$list}{randomize} = $attr->{shuffle};
! 2359: }
! 2360: if ("@state" eq "questestinterop item presentation flow response_lid render_choice flow_label response_label") {
! 2361: $answer_id = $attr->{ident};
! 2362: push(@{$$allanswers{$id}{$list}},$answer_id);
! 2363: %{$$settings{$id}{$list}{$answer_id}} = ();
! 2364: }
! 2365: # True/False
! 2366: if ("@state" eq "questestinterop item presentation flow response_lid render_choice flow_label response_label material mat_extension webct:localizable_mattext") {
! 2367: $currtexttype = lc($attr->{texttype});
! 2368: $$settings{$id}{$list}{$answer_id}{texttype} = $currtexttype;
! 2369: }
! 2370:
! 2371: # Multiple Choice and Combination
! 2372: if ("@state" eq "questestinterop item presentation flow response_lid render_choice flow_label response_label material mattext") {
! 2373: $currtexttype = lc($attr->{texttype});
! 2374: $$settings{$id}{$list}{$answer_id}{texttype} = $currtexttype;
! 2375: if ($$settings{$id}{class} eq 'combination') {
! 2376: $currtextlabel = $attr->{label};
! 2377: }
! 2378: }
! 2379:
! 2380: # String, Shortanswer or Paragraph
! 2381: if (($$settings{$id}{class} eq 'string') ||
! 2382: ($$settings{$id}{class} eq 'shortanswer') ||
! 2383: ($$settings{$id}{class} eq 'paragraph')) {
! 2384: if ("@state" eq "questestinterop item presentation flow response_str") {
! 2385: $str_id = $attr->{ident};
! 2386: %{$$settings{$id}{$str_id}} = ();
! 2387: push(@{$$settings{$id}{str}},$str_id);
! 2388: $$settings{$id}{$str_id}{rcardinality} = $attr->{rcardinality};
! 2389: @{$$settings{$id}{$str_id}{labels}} = ();
! 2390: %{$$settings{$id}{$str_id}{comparison}} = ();
! 2391: }
! 2392: }
! 2393: if ("@state" eq "questestinterop item presentation flow response_str material mattext") { # string
! 2394: $currtexttype = lc($attr->{texttype});
! 2395: $$settings{$id}{$str_id}{texttype} = $currtexttype;
! 2396: }
! 2397: if ("@state" eq "questestinterop item presentation flow response_str render_fib") {
! 2398: $fibtype = $attr->{fibtype};
! 2399: $prompt = $attr->{prompt};
! 2400: $rows = $attr->{rows};
! 2401: $columns = $attr->{columns};
! 2402: $maxchars = $attr->{maxchars};
! 2403: }
! 2404: if ("@state" eq "questestinterop item presentation flow response_str render_fib response_label") {
! 2405: push(@{$$settings{$id}{$str_id}{labels}},$label);
! 2406: @{$$settings{$id}{strings}{$str_id}} = ();
! 2407: %{$$settings{$id}{$str_id}{$label}} = ();
! 2408: $$settings{$id}{$str_id}{$label}{fibtype} = $fibtype;
! 2409: if ($$settings{$id}{class} eq 'string') {
! 2410: $$settings{$id}{text} .= '[blank]';
! 2411: }
! 2412: }
! 2413: if ("@state" eq "questestinterop item presentation flow response_str render_fib response_label material mattext") { # Paragraph
! 2414: $textlabel = $attr->{label};
! 2415: }
! 2416: # Matching
! 2417: if ("@state" eq "questestinterop item presentation flow flow response_grp") {
! 2418: $grp = $attr->{ident};
! 2419: push(@{$$settings{$id}{grps}},$grp);
! 2420: %{$$settings{$id}{$grp}} = ();
! 2421: @{$$settings{$id}{$grp}{correctanswer}} = ();
! 2422: $$settings{$id}{$grp}{rcardinality} = $attr->{rcardinality};
! 2423: }
! 2424: if ("@state" eq "questestinterop item presentation flow flow response_grp material mattext") {
! 2425: $currtexttype = lc($attr->{texttype});
! 2426: $$settings{$id}{$grp}{texttype} = $currtexttype;
! 2427: }
! 2428: if ("@state" eq "questestinterop item presentation flow flow response_grp render_choice response_label") {
! 2429: $answer_id = $attr->{ident};
! 2430: push(@{$$allanswers{$id}{$grp}},$answer_id);
! 2431: %{$$settings{$id}{$grp}{$answer_id}} = ();
! 2432: $currtexttype = lc($attr->{texttype});
! 2433: $$settings{$id}{$grp}{$answer_id}{texttype} = $currtexttype;
! 2434: }
! 2435: # Multiple choice or combination or string or match
! 2436: if ("@state" eq "questestinterop item resprocessing respcondition conditionvar varequal") {
! 2437: if (($$settings{$id}{class} eq 'multiplechoice') ||
! 2438: ($$settings{$id}{class} eq 'combination')) {
! 2439: $list = $attr->{respident};
! 2440: } elsif (($$settings{$id}{class} eq 'string') ||
! 2441: ($$settings{$id}{class} eq 'shortanswer')) {
! 2442: $label = $attr->{respident};
! 2443: } elsif ($$settings{$id}{class} eq 'match') {
! 2444: $grp = $attr->{respident};
! 2445: }
! 2446: }
! 2447: if ("@state" eq "questestinterop item resprocessing") {
! 2448: if (($$settings{$id}{class} eq 'string') ||
! 2449: ($$settings{$id}{class} eq 'shortanswer')) {
! 2450: foreach my $str_id (@{$$settings{$id}{str}}) {
! 2451: @{$str_answers{$str_id}} = ();
! 2452: }
! 2453: }
! 2454: }
! 2455: if ("@state" eq "questestinterop item resprocessing respcondition") {
! 2456: if (($$settings{$id}{class} eq 'string') ||
! 2457: ($$settings{$id}{class} eq 'shortanswer')) {
! 2458: $numbox ++;
! 2459: }
! 2460: }
! 2461: if ("@state" eq "questestinterop item resprocessing respcondition setvar") {
! 2462: foreach my $key (keys(%{$attr})) {
! 2463: $setvar{$key} = $attr->{$key};
! 2464: }
! 2465: }
! 2466: if (($$settings{$id}{class} eq 'string') ||
! 2467: ($$settings{$id}{class} eq 'shortanswer')) {
! 2468: if (("@state" eq "questestinterop item resprocessing respcondition conditionvar or varsubset") || ("@state" eq "questestinterop item resprocessing respcondition conditionvar varsubset")) {
! 2469: $str_id = $attr->{respident};
! 2470: $$settings{$id}{$str_id}{case} = $attr->{case};
! 2471: }
! 2472: }
! 2473: if ("@state" eq "questestinterop item resprocessing respcondition conditionvar and varsubset") {
! 2474: $list = $attr->{respident};
! 2475: }
! 2476: # Numerical
! 2477: if ("@state" eq "questestinterop item resprocessing itemproc_extension webct:calculated_answer") {
! 2478: $numid = $attr->{respident};
! 2479: $$settings{$id}{$numid}{toltype} = $attr->{'webct:toleranceType'};
! 2480: $$settings{$id}{$numid}{tolerance} = $attr->{'webct:tolerance'};
! 2481: }
! 2482: if ("@state" eq "questestinterop item resprocessing itemproc_extension unit_eval conditionvar varequal") {
! 2483: $unitid = $attr->{respident};
! 2484: %{$$settings{$id}{$numid}{$unitid}} = ();
! 2485: push(@{$$settings{$id}{$numid}{units}},$unitid);
! 2486: $$settings{$id}{$numid}{$unitid}{case} = $attr->{case};
! 2487: }
! 2488: # Feedback
! 2489: if ("@state" eq "questestinterop item respcondition displayfeedback") {
! 2490: $fdbk = $attr->{linkrefid};
! 2491: push(@{$$settings{$id}{feedback}},$fdbk);
! 2492: $$settings{$id}{$fdbk} = ();
! 2493: $$settings{$id}{$fdbk}{feedbacktype} = $attr->{feedbacktype};
! 2494: }
! 2495: if ("@state" eq "questestinterop item itemfeedback") {
! 2496: $fdbk = $attr->{ident};
! 2497: push(@{$$settings{$id}{feedback}},$fdbk);
! 2498: $$settings{$id}{$fdbk}{view} = $attr->{view};
! 2499: }
! 2500: if ("@state" eq "questestinterop item itemfeedback material mattext") {
! 2501: $currtexttype = lc($attr->{texttype});
! 2502: $$settings{$id}{$fdbk}{texttype} = $currtexttype;
! 2503: }
! 2504: if ("@state" eq "questestinterop item itemfeedback solution solutionmaterial material mattext") {
! 2505: $currtexttype = lc($attr->{texttype});
! 2506: $$settings{$id}{$fdbk}{texttype} = $currtexttype;
! 2507: }
! 2508: }, "tagname, attr"],
! 2509: text_h =>
! 2510: [sub {
! 2511: my ($text) = @_;
! 2512: if ($currtexttype eq '/text/html') {
! 2513: $text =~ s#(<img\ssrc=")([^"]+)">#$1../resfiles/$2#g;
! 2514: }
! 2515: if ("@state" eq "questestinterop item itemmetadata qtimetadata qtimetadatafield fieldlabel") {
! 2516: $fieldlabel = $text;
! 2517: }
! 2518: if ("@state" eq "questestinterop item itemmetadata qtimetadata qtimetadatafield fieldentry") {
! 2519: $questiondata{$fieldlabel} = $text;
! 2520: if ($fieldlabel eq 'wct_questiontype') {
! 2521: $$settings{$id}{class} = $classtypes{$text};
! 2522: } elsif ($fieldlabel eq 'wct_questioncategory') {
! 2523: $$settings{$id}{category} = $text;
! 2524: unless(exists($$catinfo{$text})) {
! 2525: %{$$catinfo{$text}} = ();
! 2526: $$catinfo{$text}{title} = $text;
! 2527: }
! 2528: push(@{$$catinfo{$text}{contents}},$id);
! 2529: }
! 2530: }
! 2531: if ("@state" eq "questestinterop item presentation flow material mat_extension webct:calculated webct:formula") {
! 2532: $formula = $text;
! 2533: }
! 2534: if ("@state" eq "questestinterop item presentation flow response_str material mattext") {
! 2535: $$settings{$id}{$str_id}{text} = $text;
! 2536: }
! 2537: if ("@state" eq "questestinterop item presentation flow response_str render_fib response_label material mattext") { # Paragraph
! 2538: if ($textlabel eq 'PRE_FILL_ANSWER') {
! 2539: $$settings{$id}{$str_id}{$label}{$textlabel} = $text;
! 2540: }
! 2541: }
! 2542: if ("@state" eq "questestinterop item presentation flow response_lid render_choice flow_label response_label material mattext") {
! 2543: $$settings{$id}{$list}{$answer_id}{text} .= $text;
! 2544: if ($$settings{$id}{class} eq 'combination') {
! 2545: if ($currtextlabel =~ /^wct_mc_answer_text\d+_\d+$/) {
! 2546: $$settings{$id}{$list}{$answer_id}{text} .= ', ';
! 2547: }
! 2548: }
! 2549: }
! 2550: if ("@state" eq "questestinterop item presentation flow response_lid render_choice flow_label response_label material mat_extension webct:localizable_mattext") {
! 2551: $$settings{$id}{$list}{$answer_id}{text} = $text;
! 2552: }
! 2553: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object material mattext") {
! 2554: $$settings{$id}{$list}{text} .= $text;
! 2555: }
! 2556: if ("@state" eq "questestinterop item presentation flow response_lid render_extension ims_render_object response_label material mattext") {
! 2557: $$settings{$id}{$list}{$jumble_item}{text} = $text;
! 2558: $$settings{$id}{$list}{text} .= $text;
! 2559: }
! 2560: if ("@state" eq "questestinterop item presentation flow material mattext") {
! 2561: $$settings{$id}{text} .= $text;
! 2562: if ($$settings{$id}{class} eq 'combination') {
! 2563: if ($textlabel =~ /^wct_question_label_\d+$/) {
! 2564: $$settings{$id}{$text} .= '<br />';
! 2565: }
! 2566: if ($textlabel =~ /^wct_cmc_single_answer_\d+$/) {
! 2567: $$settings{$id}{$text} .= '<br />';
! 2568: }
! 2569: }
! 2570: }
! 2571: if ("@state" eq "questestinterop item resprocessing itemproc_extension unit_eval conditionvar varequal") {
! 2572: $$settings{$id}{$numid}{$unitid}{text} = $text;
! 2573: }
! 2574: if ("@state" eq "questestinterop item resprocessing respcondition conditionvar varequal") {
! 2575: if (($$settings{$id}{class} eq 'string') ||
! 2576: ($$settings{$id}{class} eq 'shortanswer')) {
! 2577: unless (grep/^$text$/,@{$str_answers{$str_id}}) {
! 2578: push(@{$str_answers{$str_id}},$text);
! 2579: $$settings{$id}{$str_id}{comparison}{$text} = $questiondata{'wct_comparison_type'.$numbox};
! 2580: }
! 2581: } else {
! 2582: $answer_id = $text;
! 2583: }
! 2584: }
! 2585: if (("@state" eq "questestinterop item resprocessing respcondition conditionvar or varsubset") || ("@state" eq "questestinterop item resprocessing respcondition conditionvar varsubset")) { # string
! 2586: if (($$settings{$id}{class} eq 'string') ||
! 2587: ($$settings{$id}{class} eq 'shortanswer')) {
! 2588: unless (grep/^$text$/,@{$str_answers{$str_id}}) {
! 2589: push(@{$str_answers{$str_id}},$text);
! 2590: $$settings{$id}{$str_id}{comparison}{$text} = $questiondata{'wct_comparison_type'.$numbox};
! 2591: }
! 2592: }
! 2593: }
! 2594: if ("@state" eq "questestinterop item resprocessing respcondition conditionvar and varequal") { # Jumbled
! 2595: $$settings{$id}{$list}{jumbled}[$currindex] = $text;
! 2596: }
! 2597: if ("@state" eq "questestinterop item resprocessing respcondition setvar") {
! 2598: if ($setvar{varname} eq "SCORE") { # Multiple Choice, String or Match
! 2599: if ($text =~ m/^[\d\.]+$/) {
! 2600: if ($text > 0) {
! 2601: if (($$settings{$id}{class} eq 'multiplechoice') ||
! 2602: ($$settings{$id}{class} eq 'combination')) {
! 2603: push(@{$$settings{$id}{$list}{correctanswer}},$answer_id);
! 2604: } elsif (($$settings{$id}{class} eq 'string') ||
! 2605: ($$settings{$id}{class} eq 'shortanswer')) {
! 2606: foreach my $answer (@{$str_answers{$str_id}}) {
! 2607: unless (grep/^$answer$/,@{$$settings{$id}{strings}{$str_id}}) {
! 2608: push(@{$$settings{$id}{strings}{$str_id}},$answer);
! 2609: }
! 2610: }
! 2611: } elsif ($$settings{$id}{class} eq 'match') {
! 2612: push(@{$$settings{$id}{$grp}{correctanswer}},$answer_id);
! 2613: }
! 2614: }
! 2615: }
! 2616: }
! 2617: }
! 2618: if ("@state" eq "questestinterop item itemfeedback material mattext") {
! 2619: $$settings{$id}{$fdbk}{text} = $text;
! 2620: }
! 2621: if ("@state" eq "questestinterop item itemfeedback solution solutionmaterial material mattext") {
! 2622: $$settings{$id}{$fdbk}{text} = $text;
! 2623: }
! 2624: }, "dtext"],
! 2625: end_h =>
! 2626: [sub {
! 2627: my ($tagname) = @_;
! 2628: pop @state;
! 2629: }, "tagname"],
! 2630: );
! 2631: $p->unbroken_text(1);
! 2632: $p->parse_file($xmlfile);
! 2633: $p->eof;
! 2634: }
! 2635:
1.15 raeburn 2636: sub parse_webct4_assessment {
1.16 raeburn 2637: my ($res,$docroot,$href,$container,$allids) = @_;
2638: my $xmlfile = $docroot.'/'.$href; #quiz file
1.15 raeburn 2639: my @state = ();
2640: my $id; # the current question ID
2641: my $p = HTML::Parser->new
2642: (
2643: xml_mode => 1,
2644: start_h =>
2645: [sub {
2646: my ($tagname, $attr) = @_;
2647: push @state, $tagname;
2648: my $depth = 0;
2649: my @seq = ();
2650: if ("@state" eq "questestinterop assessment section itemref") {
2651: $id = $attr->{linkrefid};
2652: push(@{$allids},$id);
2653: }
2654: }, "tagname, attr"],
2655: text_h =>
2656: [sub {
2657: my ($text) = @_;
2658: }, "dtext"],
2659: end_h =>
2660: [sub {
2661: my ($tagname) = @_;
2662: pop @state;
2663: }, "tagname"],
2664: );
2665: $p->unbroken_text(1);
2666: $p->parse_file($xmlfile);
2667: $p->eof;
2668: }
2669:
1.16 raeburn 2670: sub parse_webct4_quizprops {
2671: my ($res,$docroot,$href,$container,$qzparams) = @_;
2672: my $xmlfile = $docroot.'/'.$href; #properties file
1.15 raeburn 2673: my @state = ();
2674: %{$$qzparams{$res}} = ();
2675: my $p = HTML::Parser->new
2676: (
2677: xml_mode => 1,
2678: start_h =>
2679: [sub {
2680: my ($tagname, $attr) = @_;
2681: push @state, $tagname;
2682: }, "tagname, attr"],
2683: text_h =>
2684: [sub {
2685: my ($text) = @_;
2686: if ($state[0] eq 'properties' && $state[1] eq 'delivery') {
1.16 raeburn 2687: if ($state[2] eq 'time_available') {
1.15 raeburn 2688: $$qzparams{$res}{opendate} = $text;
1.16 raeburn 2689: } elsif ($state[2] eq 'time_due') {
1.18 raeburn 2690: $$qzparams{$res}{duedate} = $text;
1.16 raeburn 2691: } elsif ($state[3] eq 'max_attempt') {
1.15 raeburn 2692: $$qzparams{$res}{tries} = $text;
1.16 raeburn 2693: } elsif ($state[3] eq 'post_submission') {
1.15 raeburn 2694: $$qzparams{$res}{posts} = $text;
1.18 raeburn 2695: } elsif ($state[3] eq 'method') {
2696: $$qzparams{$res}{method} = $text;
2697: }
2698: } elsif ($state[0] eq 'properties' && $state[1] eq 'processing') {
2699: if ($state[2] eq 'scores' && $state[3] eq 'score') {
2700: $$qzparams{$res}{weight} = $text;
2701: } elsif ($state[2] eq 'selection' && $state[3] eq 'select') {
2702: $$qzparams{$res}{numpick} = $text;
1.16 raeburn 2703: }
1.15 raeburn 2704: } elsif ($state[0] eq 'properties' && $state[1] eq 'result') {
1.16 raeburn 2705: if ($state[2] eq 'display_answer') {
1.18 raeburn 2706: $$qzparams{$res}{showanswer} = $text;
1.16 raeburn 2707: }
1.15 raeburn 2708: }
2709: }, "dtext"],
2710: end_h =>
2711: [sub {
2712: my ($tagname) = @_;
2713: pop @state;
2714: }, "tagname"],
2715: );
2716: $p->unbroken_text(1);
2717: $p->parse_file($xmlfile);
2718: $p->eof;
2719: }
2720:
2721: sub parse_webct4_questionDB {
1.16 raeburn 2722: my ($docroot,$href,$catinfo,$settings,$allanswers,$allchoices,$allids) = @_;
2723: $href =~ s#[^/]+$##;
2724: my $xmlfile = $docroot.'/'.$href.'questionDB.xml'; #quizDB file
1.15 raeburn 2725: my @state = ();
2726: my $category; # the current category ID
2727: my $id; # the current question ID
2728: my $list; # the current list ID for multiple choice questions
2729: my $numid; # the current answer ID for numerical questions
2730: my $grp; # the current group ID for matching questions
2731: my $label; # the current reponse label for string questions
2732: my $str_id; # the current string ID for string questions
2733: my $unitid; # the current unit ID for numerical questions
2734: my $answer_id; # the current answer ID
2735: my $fdbk; # the current feedback ID
1.16 raeburn 2736: my $currvar; # the current variable for numerical problems
2737: my $fibtype; # the current fill-in-blank type for numerical or string
2738: my $prompt;
2739: my $boxnum;
1.15 raeburn 2740: my %setvar = (
2741: varname => '',
2742: action => '',
1.16 raeburn 2743: );
2744: my $currtexttype;
2745: my $currimagtype;
1.15 raeburn 2746: my $p = HTML::Parser->new
2747: (
2748: xml_mode => 1,
2749: start_h =>
2750: [sub {
2751: my ($tagname, $attr) = @_;
2752: push @state, $tagname;
2753: if ("@state" eq "questestinterop section") {
2754: $category = $attr->{ident};
2755: %{$$catinfo{$category}} = ();
2756: $$catinfo{$category}{title} = $attr->{title};
2757: }
2758: if ("@state" eq "questestinterop section item") {
2759: $id = $attr->{ident};
2760: push @{$allids}, $id;
2761: push(@{$$catinfo{$category}{contents}},$id);
2762: %{$$settings{$id}} = ();
1.16 raeburn 2763: @{$$allchoices{$id}} = ();
1.15 raeburn 2764: @{$$settings{$id}{grps}} = ();
2765: @{$$settings{$id}{lists}} = ();
2766: @{$$settings{$id}{feedback}} = ();
1.16 raeburn 2767: @{$$settings{$id}{str}} = ();
1.15 raeburn 2768: %{$$settings{$id}{strings}} = ();
1.16 raeburn 2769: @{$$settings{$id}{numids}} = ();
2770: @{$$settings{$id}{boxes}} = ();
1.15 raeburn 2771: %{$$allanswers{$id}} = ();
2772: $$settings{$id}{title} = $attr->{title};
1.16 raeburn 2773: $$settings{$id}{category} = $category;
2774: $boxnum = 0;
1.15 raeburn 2775: }
2776:
2777: if ("@state" eq "questestinterop section item presentation material mattext") {
2778: $$settings{$id}{texttype} = $attr->{texttype};
1.16 raeburn 2779: $currtexttype = $attr->{texttype};
1.15 raeburn 2780: }
1.16 raeburn 2781: if ("@state" eq "questestinterop section item presentation material matimage") {
2782: $$settings{$id}{imagtype} = $attr->{imagtype};
2783: $currimagtype = $attr->{imagtype};
2784: $$settings{$id}{uri} = $attr->{uri};
2785: }
2786:
2787: # Matching
1.15 raeburn 2788: if ("@state" eq "questestinterop section item presentation response_grp") {
1.16 raeburn 2789: $$settings{$id}{class} = 'match';
1.15 raeburn 2790: $grp = $attr->{ident};
2791: push(@{$$settings{$id}{grps}},$grp);
2792: %{$$settings{$id}{$grp}} = ();
2793: @{$$settings{$id}{$grp}{correctanswer}} = ();
2794: $$settings{$id}{$grp}{rcardinality} = $attr->{rcardinality};
2795: }
2796: if ("@state" eq "questestinterop section item presentation response_grp material mattext") {
2797: $$settings{$id}{$grp}{texttype} = $attr->{texttype};
1.16 raeburn 2798: $currtexttype = $attr->{texttype};
1.15 raeburn 2799: }
2800: if ("@state" eq "questestinterop section item presentation response_grp render_choice response_label") {
2801: $answer_id = $attr->{ident};
2802: push(@{$$allanswers{$id}{$grp}},$answer_id);
2803: %{$$settings{$id}{$grp}{$answer_id}} = ();
2804: $$settings{$id}{$grp}{$answer_id}{texttype} = $attr->{texttype};
1.16 raeburn 2805: $currtexttype = $attr->{texttype};
1.15 raeburn 2806: }
2807:
2808: # Multiple choice
2809:
2810: if ("@state" eq "questestinterop section item presentation flow material mattext") {
2811: $$settings{$id}{texttype} = $attr->{texttype};
1.16 raeburn 2812: $currtexttype = $attr->{texttype};
1.15 raeburn 2813: }
2814: if ("@state" eq "questestinterop section item presentation flow response_lid") {
1.16 raeburn 2815: $$settings{$id}{class} = 'multiplechoice';
1.15 raeburn 2816: $list = $attr->{ident};
2817: push(@{$$settings{$id}{lists}},$list);
2818: %{$$settings{$id}{$list}} = ();
2819: @{$$allanswers{$id}{$list}} = ();
2820: @{$$settings{$id}{$list}{correctanswer}} = ();
2821: $$settings{$id}{$list}{rcardinality} = $attr->{rcardinality};
2822: }
2823: if ("@state" eq "questestinterop section item presentation flow response_lid render_choice") {
2824: $$settings{$id}{$list}{randomize} = $attr->{shuffle};
2825: }
2826: if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label") {
2827: $answer_id = $attr->{ident};
2828: push(@{$$allanswers{$id}{$list}},$answer_id);
2829: %{$$settings{$id}{$list}{$answer_id}} = ();
2830: }
2831: if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label material mattext") {
2832: $$settings{$id}{$list}{$answer_id}{texttype} = $attr->{texttype};
1.16 raeburn 2833: $currtexttype = $attr->{texttype};
1.15 raeburn 2834: }
2835:
2836: # Numerical
2837: if ("@state" eq "questestinterop section item presentation material mat_extension webct:x_webct_v01_dynamicmattext") {
2838: $$settings{$id}{texttype} = $attr->{texttype};
1.16 raeburn 2839: $currtexttype = $attr->{texttype};
1.15 raeburn 2840: }
2841: if ("@state" eq "questestinterop section item presentation response_num") {
1.16 raeburn 2842: $$settings{$id}{class} = 'numerical';
1.15 raeburn 2843: $numid = $attr->{ident};
1.16 raeburn 2844: push(@{$$settings{$id}{numids}},$numid);
1.15 raeburn 2845: %{$$settings{$id}{$numid}} = ();
1.16 raeburn 2846: %{$$settings{$id}{$numid}{vars}} = ();
2847: @{$$settings{$id}{$numid}{units}} = ();
1.15 raeburn 2848: $$settings{$id}{$numid}{rcardinality} = $attr->{rcardinality};
2849: }
2850: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_minvalue webct:x_webct_v01_variable") {
1.16 raeburn 2851: $currvar = $attr->{name};
2852: %{$$settings{$id}{$numid}{vars}{$currvar}} = ();
1.15 raeburn 2853: }
1.16 raeburn 2854: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_maxvalue webct:x_webct_v01_variable") {
2855: $currvar = $attr->{name};
1.15 raeburn 2856: }
2857: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_decimalnum webct:x_webct_v01_variable") {
1.16 raeburn 2858: $currvar = $attr->{name};
1.15 raeburn 2859: }
2860: if ("@state" eq "questestinterop section item presentation response_num render_fib") {
2861: $fibtype = $attr->{fibtype};
2862: $prompt = $attr->{prompt};
2863: }
2864: if ("@state" eq "questestinterop section item presentation response_num render_fib response_label") {
2865: $$settings{$id}{$numid}{label} = $attr->{ident};
2866: }
2867:
2868: # String or Numerical
2869: if ("@state" eq "questestinterop section item presentation response_str") {
2870: $str_id = $attr->{ident};
2871: push(@{$$settings{$id}{str}},$str_id);
1.16 raeburn 2872: @{$$settings{$id}{boxes}[$boxnum]} = ();
2873: $boxnum ++;
1.15 raeburn 2874: %{$$settings{$id}{$str_id}} = ();
1.16 raeburn 2875: @{$$settings{$id}{$str_id}{labels}} = ();
1.15 raeburn 2876: $$settings{$id}{$str_id}{rcardinality} = $attr->{rcardinality};
2877: }
2878:
2879: if ("@state" eq "questestinterop section item presentation response_str render_fib") {
2880: $fibtype = $attr->{fibtype};
1.16 raeburn 2881: $prompt = $attr->{prompt};
1.15 raeburn 2882: }
2883: if ("@state" eq "questestinterop section item presentation response_str render_fib response_label") {
2884: $label = $attr->{ident};
1.16 raeburn 2885: push(@{$$settings{$id}{$str_id}{labels}},$label);
2886: @{$$settings{$id}{strings}{$label}} = ();
1.15 raeburn 2887: %{$$settings{$id}{$str_id}{$label}} = ();
2888: $$settings{$id}{$str_id}{$label}{fibtype} = $fibtype;
2889: }
2890:
2891: # Numerical
2892: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_anspresentation") {
2893: $$settings{$id}{$numid}{digits} = $attr->{digits};
2894: $$settings{$id}{$numid}{format} = $attr->{format};
2895: }
2896: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_anstolerance") {
2897: $$settings{$id}{$numid}{toltype} = $attr->{type};
2898: }
2899: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_unit") {
1.26 raeburn 2900: $unitid = $attr->{ident};
1.15 raeburn 2901: %{$$settings{$id}{$numid}{$unitid}} = ();
1.16 raeburn 2902: push(@{$$settings{$id}{$numid}{units}},$unitid);
1.15 raeburn 2903: $$settings{$id}{$numid}{$unitid}{value} = $attr->{value};
2904: $$settings{$id}{$numid}{$unitid}{space} = $attr->{space};
2905: $$settings{$id}{$numid}{$unitid}{case} = $attr->{case};
2906: }
2907:
2908: # Matching
2909: if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
1.16 raeburn 2910: if ($$settings{$id}{class} eq 'match') {
2911: unless ($attr->{respident} eq 'WebCT_Incorrect') {
2912: $grp = $attr->{respident};
2913: }
2914: # String
2915: } else {
2916: $label = $attr->{respident};
2917: $$settings{$id}{$label}{case} = $attr->{case};
2918: }
1.15 raeburn 2919: }
1.16 raeburn 2920: if ("@state" eq "questestinterop section item resprocessing respcondition setvar") {
1.15 raeburn 2921: $setvar{varname} = $attr->{varname};
2922: if ($setvar{varname} eq 'WebCT_Correct') {
2923: push(@{$$settings{$id}{$grp}{correctanswer}},$answer_id);
2924: }
2925: }
2926:
1.16 raeburn 2927: # String
2928: if ("@state" eq "questestinterop section item resprocessing") {
2929: $boxnum = -1;
2930: }
2931: if ("@state" eq "questestinterop section item resprocessing respcondition") { $boxnum ++;
2932: }
1.15 raeburn 2933: if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varsubset") {
1.16 raeburn 2934: $$settings{$id}{class} = 'string';
2935: $label = $attr->{respident};
1.15 raeburn 2936: }
2937: if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar not") {
1.16 raeburn 2938: $$settings{$id}{class} = 'paragraph';
1.15 raeburn 2939: }
2940:
2941:
2942: # Feedback
2943:
2944: if ("@state" eq "questestinterop section item respcondition displayfeedback") {
2945: $fdbk = $attr->{linkrefid};
2946: push(@{$$settings{$id}{feedback}},$fdbk);
2947: $$settings{$id}{$fdbk} = ();
2948: $$settings{$id}{$fdbk}{feedbacktype} = $attr->{feedbacktype};
2949: }
2950: if ("@state" eq "questestinterop section item itemfeedback") {
2951: $fdbk = $attr->{ident};
2952: $$settings{$id}{$fdbk}{view} = $attr->{view};
2953: }
2954: if ("@state" eq "questestinterop section item itemfeedback material mattext") {
2955: $$settings{$id}{$fdbk}{texttype} = $attr->{texttype};
1.16 raeburn 2956: $currtexttype = $attr->{texttype};
1.15 raeburn 2957: }
2958: }, "tagname, attr"],
2959: text_h =>
2960: [sub {
2961: my ($text) = @_;
1.16 raeburn 2962: if ($currtexttype eq '/text/html') {
2963: $text =~ s#(<img\ssrc=")([^"]+)">#$1../resfiles/$2#g;
2964: }
1.15 raeburn 2965: if ("@state" eq "questestinterop section item itemmetadata qmd_itemtype") {
2966: $$settings{$id}{itemtype} = $text;
1.16 raeburn 2967: if ($text eq 'String') {
2968: $$settings{$id}{class} = 'string';
2969: }
1.15 raeburn 2970: }
2971:
2972: if ("@state" eq "questestinterop section item presentation material mattext") {
2973: $$settings{$id}{text} = $text;
2974: }
1.16 raeburn 2975: # Matching
1.15 raeburn 2976: if ("@state" eq "questestinterop section item presentation response_grp material mattext") {
2977: $$settings{$id}{$grp}{text} = $text;
1.16 raeburn 2978: unless ($text eq '') {
2979: push(@{$$allchoices{$id}},$grp);
2980: }
1.15 raeburn 2981: }
2982: if ("@state" eq "questestinterop section item presentation response_grp render_choice response_label material mattext") {
2983: $$settings{$id}{$grp}{$answer_id}{text} = $text;
2984: }
2985:
2986: # Multiple choice
2987:
2988: if ("@state" eq "questestinterop section item presentation flow material mattext") {
2989: $$settings{$id}{text} = $text;
2990: }
2991:
2992: if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow_label response_label material mattext") {
2993: $$settings{$id}{$list}{$answer_id}{text} = $text;
2994: }
2995:
2996: # Numerical
2997: if ("@state" eq "questestinterop section item presentation material mat_extension webct:x_webct_v01_dynamicmattext") {
2998: $$settings{$id}{text} = $text;
2999: }
3000: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_minvalue webct:x_webct_v01_variable") {
1.16 raeburn 3001: $$settings{$id}{$numid}{vars}{$currvar}{min} = $text;
1.15 raeburn 3002: }
3003: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_maxvalue webct:x_webct_v01_variable") {
1.16 raeburn 3004: $$settings{$id}{$numid}{vars}{$currvar}{max} = $text;
1.15 raeburn 3005: }
3006: if ("@state" eq "questestinterop section item presentation response_num material mat_extension webct:x_webct_v01_dynamicdata webct:x_webct_v01_datarange webct:x_webct_v01_decimalnum webct:x_webct_v01_variable") {
1.16 raeburn 3007: $$settings{$id}{$numid}{vars}{$currvar}{dec} = $text;
3008: }
3009: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_formula") {
3010: $$settings{$id}{$numid}{formula} = $text;
1.15 raeburn 3011: }
3012: if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
1.16 raeburn 3013: if ($$settings{$id}{class} eq 'string') {
3014: unless (grep/^$text$/,@{$$settings{$id}{strings}{$label}}) {
3015: push(@{$$settings{$id}{strings}{$label}},$text);
3016: }
3017: unless (grep/^$text$/,@{$$settings{$id}{boxes}[$boxnum]}) {
3018: push(@{$$settings{$id}{boxes}[$boxnum]},$text);
3019: }
3020: } else {
3021: $answer_id = $text;
3022: }
1.15 raeburn 3023: }
3024: if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varsubset") { # String
1.16 raeburn 3025: unless (grep/^$text$/,@{$$settings{$id}{strings}{$label}}) {
3026: push(@{$$settings{$id}{strings}{$label}},$text);
3027: }
3028: unless (grep/^$text$/,@{$$settings{$id}{boxes}[$boxnum]}) {
3029: push(@{$$settings{$id}{boxes}[$boxnum]},$text);
3030: }
1.15 raeburn 3031: }
1.16 raeburn 3032: if ("@state" eq "questestinterop section item resprocessing respcondition setvar") {
1.15 raeburn 3033: if ($setvar{varname} eq "answerValue") { # Multiple Choice
3034: if ($text =~ m/^\d+$/) {
3035: if ($text > 0) {
1.16 raeburn 3036: push(@{$$settings{$id}{$list}{correctanswer}},$answer_id);
1.15 raeburn 3037: }
3038: }
3039: }
3040: }
1.16 raeburn 3041: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_anstolerance") {
3042: $$settings{$id}{$numid}{tolerance} = $text;
3043: }
1.15 raeburn 3044: if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_unit") {
3045: $$settings{$id}{$numid}{$unitid}{text} = $text;
3046: }
3047:
3048: if ("@state" eq "questestinterop section item itemfeedback material mattext") {
3049: $$settings{$id}{$fdbk}{text} = $text;
3050: }
3051: }, "dtext"],
3052: end_h =>
3053: [sub {
3054: my ($tagname) = @_;
3055: pop @state;
3056: }, "tagname"],
3057: );
3058: $p->unbroken_text(1);
3059: $p->parse_file($xmlfile);
3060: $p->eof;
1.16 raeburn 3061: my $boxcount;
3062: foreach my $id (keys %{$settings}) {
3063: if ($$settings{$id}{class} eq 'string') {
3064: $boxcount = 0;
3065: if (@{$$settings{$id}{boxes}} > 1) {
3066: foreach my $str_id (@{$$settings{$id}{str}}) {
3067: foreach my $label (@{$$settings{$id}{$str_id}{labels}}) {
3068: @{$$settings{$id}{strings}{$label}} = @{$$settings{$id}{boxes}[$boxcount]};
3069: $boxcount ++;
3070: }
3071: }
3072: }
3073: }
3074: }
1.15 raeburn 3075: }
1.2 raeburn 3076:
1.15 raeburn 3077: sub process_assessment {
1.35 ! raeburn 3078: my ($cms,$context,$res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,$dbparse,$resources,$items,$catinfo,$qzdbsettings,$hrefs,$allquestions) = @_;
1.15 raeburn 3079: my @allids = ();
1.35 ! raeburn 3080: my @allquestids = ();
1.15 raeburn 3081: my %allanswers = ();
3082: my %allchoices = ();
3083: my %qzparams = ();
3084: my %alldbanswers = ();
3085: my %alldbchoices = ();
3086: my @alldbquestids = ();
3087: my $containerdir;
3088: my $newdir;
3089: my $randompickflag = 0;
3090: my ($cid,$cdom,$cnum);
3091: if ($context eq 'DOCS') {
1.19 albertel 3092: $cid = $env{'request.course.id'};
1.15 raeburn 3093: ($cdom,$cnum) = split/_/,$cid;
3094: }
3095: my $destresdir = $destdir;
3096: if ($context eq 'CSTR') {
3097: $destresdir =~ s|/home/$uname/public_html/|/res/$udom/$uname/|;
3098: } elsif ($context eq 'DOCS') {
3099: $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
3100: }
3101: if ($cms eq 'bb5') {
3102: &parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids);
3103: } elsif ($cms eq 'bb6') {
1.30 raeburn 3104: &parse_bb6_assessment($res,$docroot,$container,$settings,\@allids);
1.34 raeburn 3105: } elsif ($cms eq 'webctce4') {
1.15 raeburn 3106: unless($$dbparse) {
1.17 raeburn 3107: &parse_webct4_questionDB($docroot,$$resources{$res}{file},$catinfo,$qzdbsettings,\%alldbanswers,\%alldbchoices,\@alldbquestids);
1.35 ! raeburn 3108: &build_category_sequences($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings);
! 3109: &write_webct4_questions($cms,\@alldbquestids,$context,$qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo);
1.15 raeburn 3110: $$dbparse = 1;
3111: }
1.16 raeburn 3112: &parse_webct4_assessment($res,$docroot,$$resources{$res}{file},$container,\@allids);
1.18 raeburn 3113: &parse_webct4_quizprops($res,$docroot,$$hrefs{$$items{$$resources{$res}{revitm}}{properties}}[0],$container,\%qzparams);
3114: if (exists($qzparams{$res}{numpick})) {
3115: if ($qzparams{$res}{numpick} < @allids) {
3116: $$randompicks{$$resources{$res}{revitm}} = $qzparams{$res}{numpick};
3117: $randompickflag = 1;
1.15 raeburn 3118: }
3119: }
1.35 ! raeburn 3120: } elsif ($cms eq 'webctvista4') {
! 3121: unless($$dbparse) {
! 3122: foreach my $res (sort keys %{$allquestions}) {
! 3123: my $parent = $$allquestions{$res};
! 3124: &parse_webctvista4_question($res,$docroot,$resources,$hrefs,$settings,\@allquestids,\%allanswers,\%allchoices,$parent,$catinfo);
! 3125: }
! 3126: &build_category_sequences($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings);
! 3127: $$dbparse = 1;
! 3128: }
! 3129: &parse_webctvista4_assessment($res,$docroot,$hrefs,\@allids,\%qzparams);
! 3130: if ($qzparams{$res}{numpick} < @allids) {
! 3131: $$randompicks{$$resources{$res}{revitm}} = $qzparams{$res}{numpick};
! 3132: $randompickflag = 1;
! 3133: }
1.15 raeburn 3134: }
1.16 raeburn 3135: my $dirtitle;
1.34 raeburn 3136: unless ($cms eq 'webctce4') {
1.16 raeburn 3137: $dirtitle = $$settings{'title'};
3138: $dirtitle =~ s/\W//g;
3139: $dirtitle .= '_'.$res;
3140: if (!-e "$destdir/problems") {
3141: mkdir("$destdir/problems",0755);
3142: }
3143: if (!-e "$destdir/problems/$dirtitle") {
3144: mkdir("$destdir/problems/$dirtitle",0755);
3145: }
1.20 raeburn 3146: $newdir = "$destdir/problems/$dirtitle";
1.11 raeburn 3147: }
1.15 raeburn 3148:
1.34 raeburn 3149: if ($cms eq 'webctce4') {
1.20 raeburn 3150: &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
3151: } else {
3152: &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$settings);
3153: }
1.15 raeburn 3154: if ($cms eq 'bb5') {
1.20 raeburn 3155: &write_bb5_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot);
1.15 raeburn 3156: } elsif ($cms eq 'bb6') {
1.30 raeburn 3157: &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot);
1.35 ! raeburn 3158: } elsif ($cms eq 'webctvista4') {
! 3159: &write_webct4_questions($cms,\@allquestids,$context,$settings,$dirname,\%allanswers,\%allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo);
1.15 raeburn 3160: }
3161: }
3162:
1.35 ! raeburn 3163: sub build_category_sequences {
! 3164: my ($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings) = @_;
! 3165: if (!-e "$destdir/sequences") {
! 3166: mkdir("$destdir/sequences",0755);
! 3167: }
! 3168: my $numcats = scalar(keys %{$catinfo});
! 3169: my $curr_id = 0;
! 3170: my $next_id = 1;
! 3171: my $fh;
! 3172: open($fh,">$destdir/sequences/question_database.sequence");
! 3173: push @{$sequencesfiles},'question_database.sequence';
! 3174: foreach my $category (sort keys %{$catinfo}) {
! 3175: my $seqname = $$catinfo{$category}{title}.'_'.$category;
! 3176: $seqname =~ s/\s/_/g;
! 3177: $seqname =~ s/\W//g;
! 3178: push(@{$sequencesfiles},$seqname.'.sequence');
! 3179: my $catsrc = "$destresdir/sequences/$seqname.sequence";
! 3180: if ($curr_id == 0) {
! 3181: print $fh qq|<resource id="1" src="$catsrc" type="start" title="$$catinfo{$category}{title}"></resource>|;
! 3182: }
! 3183: if ($numcats == 1) {
! 3184: print $fh qq|
! 3185: <link from="1" to="2" index="1"></link>
! 3186: <resource id="2" src="" type="finish">\n|;
! 3187: } else {
! 3188: $curr_id = $next_id;
! 3189: $next_id = $curr_id + 1;
! 3190: $catsrc = "$destresdir/sequences/$seqname.sequence";
! 3191: print $fh qq|
! 3192: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
! 3193: <resource id="$next_id" src="$catsrc" title="$$catinfo{$category}{title}"|;
! 3194: if ($next_id == $numcats) {
! 3195: print $fh qq| type="finish"></resource>\n|;
! 3196: } else {
! 3197: print $fh qq|></resource>\n|;
! 3198: }
! 3199: }
! 3200: print $fh qq|</map>|;
! 3201: if (!-e "$destdir/problems") {
! 3202: mkdir("$destdir/problems",0755);
! 3203: }
! 3204: if (!-e "$destdir/problems/$seqname") {
! 3205: mkdir("$destdir/problems/$seqname",0755);
! 3206: }
! 3207: $$newdir = "$destdir/problems/$seqname";
! 3208: my $dbcontainerdir;
! 3209: &build_problem_container($cms,$seqname,$destdir,'database',$seqname,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@{$$catinfo{$category}{contents}},$udom,$uname,$dirname,\$dbcontainerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
! 3210: }
! 3211: close($fh);
! 3212: }
! 3213:
1.15 raeburn 3214: sub build_problem_container {
1.16 raeburn 3215: my ($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,$allids,$udom,$uname,$dirname,$containerdir,$cid,$cdom,$cnum,$catinfo,$settings) = @_;
1.11 raeburn 3216: my $seqdir = "$destdir/sequences";
1.2 raeburn 3217: my $pagedir = "$destdir/pages";
3218: my $curr_id = 0;
3219: my $next_id = 1;
1.11 raeburn 3220: my $fh;
1.15 raeburn 3221: if ($container eq 'pool' || $randompickflag || $container eq 'database') {
3222: $$containerdir = $seqdir.'/'.$res.'.sequence';
1.11 raeburn 3223: if (!-e "$seqdir") {
3224: mkdir("$seqdir",0770);
3225: }
1.15 raeburn 3226: open($fh,">$$containerdir");
1.11 raeburn 3227: $$total{seq} ++;
3228: push @{$sequencesfiles},$res.'.sequence';
3229: } else {
1.15 raeburn 3230: $$containerdir = $pagedir.'/'.$res.'.page';
1.11 raeburn 3231: if (!-e "$destdir/pages") {
3232: mkdir("$destdir/pages",0770);
3233: }
1.15 raeburn 3234: open($fh,">$$containerdir");
1.11 raeburn 3235: $$total{page} ++;
3236: push @{$pagesfiles},$res.'.page';
3237: }
3238: print $fh qq|<map>
3239: |;
1.17 raeburn 3240: my %probtitle = ();
1.12 raeburn 3241: my $probsrc = "/res/lib/templates/simpleproblem.problem";
3242: if ($context eq 'CSTR') {
1.17 raeburn 3243: foreach my $id (@{$allids}) {
1.35 ! raeburn 3244: if (($cms eq 'webctce4') || ($cms eq 'webctvista4')) {
1.20 raeburn 3245: $probtitle{$id} = $$settings{$id}{title};
3246: } else {
3247: $probtitle{$id} = $$settings{title};
3248: }
1.17 raeburn 3249: $probtitle{$id} =~ s/\s/_/g;
3250: $probtitle{$id} =~ s/\W//g;
3251: $probtitle{$id} .= '_'.$id;
3252: }
1.34 raeburn 3253: if ($cms eq 'webctce4' && $container ne 'database') {
1.16 raeburn 3254: my $catid = $$settings{$$allids[0]}{category};
3255: my $probdir = $$catinfo{$catid}{title}.'_'.$catid;
3256: $probdir =~ s/\s/_/g;
3257: $probdir =~ s/\W//g;
1.17 raeburn 3258: $probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[0]}.problem";
1.16 raeburn 3259: } else {
1.20 raeburn 3260: $probsrc="$dirname/problems/$dirtitle/$probtitle{$$allids[0]}.problem";
1.16 raeburn 3261: }
1.12 raeburn 3262: }
1.11 raeburn 3263: print $fh qq|<resource id="1" src="$probsrc" type="start" title="question_0001"></resource>|;
1.15 raeburn 3264: if (@{$allids} == 1) {
1.11 raeburn 3265: print $fh qq|
1.2 raeburn 3266: <link from="1" to="2" index="1"></link>
3267: <resource id="2" src="" type="finish">\n|;
1.11 raeburn 3268: } else {
1.15 raeburn 3269: for (my $j=1; $j<@{$allids}; $j++) {
3270: my $qntitle = $j+1;
1.11 raeburn 3271: while (length($qntitle) <4) {
3272: $qntitle = '0'.$qntitle;
3273: }
3274: $curr_id = $j;
3275: $next_id = $curr_id + 1;
3276: if ($context eq 'CSTR') {
1.34 raeburn 3277: if ($cms eq 'webctce4' && $container ne 'database') {
1.16 raeburn 3278: my $catid = $$settings{$$allids[$j]}{category};
3279: my $probdir = $$catinfo{$catid}{title}.'_'.$catid;
3280: $probdir =~ s/\s/_/g;
3281: $probdir =~ s/\W//g;
1.17 raeburn 3282: $probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[$j]}.problem";
1.16 raeburn 3283: } else {
1.20 raeburn 3284: $probsrc = "$dirname/problems/$dirtitle/$probtitle{$$allids[$j]}.problem";
1.16 raeburn 3285: }
1.11 raeburn 3286: }
3287: print $fh qq|
1.2 raeburn 3288: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
1.11 raeburn 3289: <resource id="$next_id" src="$probsrc" title="question_$qntitle"|;
1.15 raeburn 3290: if ($next_id == @{$allids}) {
1.11 raeburn 3291: print $fh qq| type="finish"></resource>\n|;
3292: } else {
3293: print $fh qq|></resource>|;
1.2 raeburn 3294: }
3295: }
3296: }
1.11 raeburn 3297: print $fh qq|</map>|;
3298: close($fh);
1.15 raeburn 3299: }
3300:
3301: sub write_bb5_questions {
1.20 raeburn 3302: my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
1.12 raeburn 3303: my $qnum = 0;
1.33 raeburn 3304: my $pathstart;
3305: if ($context eq 'CSTR') {
3306: $pathstart = '../..';
3307: } else {
3308: $pathstart = $dirname;
3309: }
1.15 raeburn 3310: foreach my $id (@{$allids}) {
1.20 raeburn 3311: if ($$settings{$id}{ishtml} eq 'true') {
3312: $$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text});
3313: }
3314: if ($$settings{$id}{text} =~ m#<img src=['"]?(https?://[^\s]+/)([^/\s\'"]+)['"]?[^>]*>#) {
3315: if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') {
1.33 raeburn 3316: $$settings{$id}{text} =~ s#(<img src=['"]?)(https?://[^\s]+/)([^/\s'"]+)(['"]?[^>]*>)#$1$pathstart/resfiles/$res/webimages/$3$4#g;
1.20 raeburn 3317: }
3318: }
3319: $$settings{$id}{text} =~ s#(<img src=[^>]+)/*>#$1 />#gi;
3320: $$settings{$id}{text} =~ s#<br>#<br />#g;
1.12 raeburn 3321: $qnum ++;
1.11 raeburn 3322: my $output;
1.12 raeburn 3323: my $permcontainer = $containerdir;
3324: $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
3325: my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
3326: my %resourcedata = ();
3327: for (my $i=0; $i<10; $i++) {
3328: my $iter = $i+1;
3329: $resourcedata{$symb.'text'.$iter} = "";
3330: $resourcedata{$symb.'value'.$iter} = "unused";
3331: $resourcedata{$symb.'position'.$iter} = "random";
1.15 raeburn 3332: }
1.12 raeburn 3333: $resourcedata{$symb.'randomize'} = 'yes';
3334: $resourcedata{$symb.'maxfoils'} = 10;
1.11 raeburn 3335: if ($context eq 'CSTR') {
3336: $output = qq|<problem>
1.2 raeburn 3337: |;
1.11 raeburn 3338: }
1.3 raeburn 3339: $$total{prob} ++;
1.2 raeburn 3340: if ($$settings{$id}{class} eq "QUESTION_ESSAY") {
1.11 raeburn 3341: if ($context eq 'CSTR') {
3342: $output .= qq|<startouttext />$$settings{$id}{text}<endouttext />
1.2 raeburn 3343: <essayresponse>
3344: <textfield></textfield>
3345: </essayresponse>
3346: <postanswerdate>
1.15 raeburn 3347: $$settings{$id}{feedbackcorr}
1.2 raeburn 3348: </postanswerdate>
3349: |;
1.12 raeburn 3350: } else {
3351: $resourcedata{$symb.'questiontext'} = $$settings{$id}{text};
3352: $resourcedata{$symb.'hiddenparts'} = '!essay';
3353: $resourcedata{$symb.'questiontype'} = 'essay';
1.11 raeburn 3354: }
1.2 raeburn 3355: } else {
1.11 raeburn 3356: if ($context eq 'CSTR') {
3357: $output .= qq|<startouttext />$$settings{$id}{text}\n|;
1.12 raeburn 3358: } else {
3359: $resourcedata{$symb.'questiontext'} = $$settings{$id}{text};
1.11 raeburn 3360: }
3361: my ($image,$imglink,$url);
3362: if ( defined($$settings{$id}{image}) ) {
1.2 raeburn 3363: if ( $$settings{$id}{style} eq 'embed' ) {
1.33 raeburn 3364: $image = qq|<br /><img src="$pathstart/resfiles/$res/$$settings{$id}{image}" /><br />|;
1.2 raeburn 3365: } else {
1.33 raeburn 3366: $imglink = qq|<br /><a href="$pathstart/resfiles/$res/$$settings{$id}{image}">Link to file</a><br />|;
1.2 raeburn 3367: }
3368: }
3369: if ( defined($$settings{$id}{url}) ) {
1.11 raeburn 3370: $url = qq|<br /><a href="$$settings{$id}{url}">$$settings{$id}{name}</a><br />|;
3371: }
3372: if ($context eq 'CSTR') {
3373: $output .= $image.$imglink.$url.'
3374: <endouttext />';
1.12 raeburn 3375: } else {
3376: $resourcedata{$symb.'questiontext'} .= $image.$imglink.$url;
1.2 raeburn 3377: }
3378: if ($$settings{$id}{class} eq 'QUESTION_MULTIPLECHOICE') {
1.15 raeburn 3379: my $numfoils = @{$$allanswers{$id}};
1.11 raeburn 3380: if ($context eq 'CSTR') {
3381: $output .= qq|
1.2 raeburn 3382: <radiobuttonresponse max="$numfoils" randomize="yes">
3383: <foilgroup>
3384: |;
1.12 raeburn 3385: } else {
3386: $resourcedata{$symb.'hiddenparts'} = '!radio';
3387: $resourcedata{$symb.'questiontype'} = 'radio';
3388: $resourcedata{$symb.'maxfoils'} = $numfoils;
1.11 raeburn 3389: }
1.15 raeburn 3390: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
1.12 raeburn 3391: my $iter = $k+1;
1.2 raeburn 3392: $output .= " <foil name=\"foil".$k."\" value=\"";
1.15 raeburn 3393: if (grep/^$$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1.2 raeburn 3394: $output .= "true\" location=\"";
1.12 raeburn 3395: $resourcedata{$symb.'value'.$iter} = "true";
1.2 raeburn 3396: } else {
3397: $output .= "false\" location=\"";
1.12 raeburn 3398: $resourcedata{$symb.'value'.$iter} = "false";
1.2 raeburn 3399: }
1.16 raeburn 3400: if (lc ($$allanswers{$id}[$k]) =~ m/^\s?([Aa]ll)|([Nn]one)\s(of\s)?the\sabove\.?/) {
1.2 raeburn 3401: $output .= "bottom\"";
1.12 raeburn 3402: $resourcedata{$symb.'position'.$iter} = "bottom";
1.2 raeburn 3403: } else {
3404: $output .= "random\"";
3405: }
1.15 raeburn 3406: $output .= "\><startouttext />".$$settings{$id}{$$allanswers{$id}[$k]}{text};
3407: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.11 raeburn 3408: my ($ans_image,$ans_link);
1.15 raeburn 3409: if ( defined($$settings{$id}{$$allanswers{$id}[$k]}{image}) ) {
3410: if ( $$settings{$id}{$$allanswers{$id}[$k]}{style} eq 'embed' ) {
1.33 raeburn 3411: $ans_image .= qq|<br /><img src="$pathstart/resfiles/$res/$$settings{$id}{$$allanswers{$id}[$k]}{image}" /><br />|;
1.2 raeburn 3412: } else {
1.33 raeburn 3413: $ans_link .= qq|<br /><a href="$pathstart/resfiles/$res/$$settings{$id}{$$allanswers{$id}[$k]}{image}" />Link to file</a><br/>|;
1.2 raeburn 3414: }
3415: }
1.11 raeburn 3416: $output .= $ans_image.$ans_link.'<endouttext /></foil>'."\n";
1.12 raeburn 3417: $resourcedata{$symb.'text'.$iter} .= $ans_image.$ans_link;
1.2 raeburn 3418: }
1.11 raeburn 3419: if ($context eq 'CSTR') {
3420: chomp($output);
3421: $output .= qq|
1.2 raeburn 3422: </foilgroup>
3423: </radiobuttonresponse>
3424: |;
1.11 raeburn 3425: }
1.2 raeburn 3426: } elsif ($$settings{$id}{class} eq 'QUESTION_TRUEFALSE') {
1.15 raeburn 3427: my $numfoils = @{$$allanswers{$id}};
1.11 raeburn 3428: if ($context eq 'CSTR') {
3429: $output .= qq|
1.2 raeburn 3430: <radiobuttonresponse max="$numfoils" randomize="yes">
3431: <foilgroup>
3432: |;
1.12 raeburn 3433: } else {
3434: $resourcedata{$symb.'maxfoils'} = $numfoils;
3435: $resourcedata{$symb.'hiddenparts'} = '!radio';
3436: $resourcedata{$symb.'questiontype'} = 'radio';
1.11 raeburn 3437: }
1.15 raeburn 3438: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
1.12 raeburn 3439: my $iter = $k+1;
1.2 raeburn 3440: $output .= " <foil name=\"foil".$k."\" value=\"";
1.15 raeburn 3441: if (grep/^$$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1.2 raeburn 3442: $output .= "true\" location=\"random\"";
1.12 raeburn 3443: $resourcedata{$symb.'value'.$iter} = "true";
1.2 raeburn 3444: } else {
3445: $output .= "false\" location=\"random\"";
1.12 raeburn 3446: $resourcedata{$symb.'value'.$iter} = "false";
1.2 raeburn 3447: }
1.15 raeburn 3448: $output .= "\><startouttext />".$$settings{$id}{$$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
3449: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.2 raeburn 3450: }
1.11 raeburn 3451: if ($context eq 'CSTR') {
3452: chomp($output);
3453: $output .= qq|
1.2 raeburn 3454: </foilgroup>
3455: </radiobuttonresponse>
3456: |;
1.11 raeburn 3457: }
1.2 raeburn 3458: } elsif ($$settings{$id}{class} eq 'QUESTION_MULTIPLEANSWER') {
1.15 raeburn 3459: my $numfoils = @{$$allanswers{$id}};
1.11 raeburn 3460: if ($context eq 'CSTR') {
3461: $output .= qq|
1.2 raeburn 3462: <optionresponse max="$numfoils" randomize="yes">
3463: <foilgroup options="('True','False')">
3464: |;
1.12 raeburn 3465: } else {
3466: $resourcedata{$symb.'newopt'} = '';
3467: $resourcedata{$symb.'delopt'} = '';
3468: $resourcedata{$symb.'options'} = "('True','False')";
3469: $resourcedata{$symb.'hiddenparts'} = '!option';
3470: $resourcedata{$symb.'questiontype'} = 'option';
3471: $resourcedata{$symb.'maxfoils'} = $numfoils;
1.11 raeburn 3472: }
1.15 raeburn 3473: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
1.12 raeburn 3474: my $iter = $k+1;
1.2 raeburn 3475: $output .= " <foil name=\"foil".$k."\" value=\"";
1.15 raeburn 3476: if (grep/^$$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1.2 raeburn 3477: $output .= "True\"";
1.12 raeburn 3478: $resourcedata{$symb.'value'.$iter} = "True";
1.2 raeburn 3479: } else {
3480: $output .= "False\"";
1.12 raeburn 3481: $resourcedata{$symb.'value'.$iter} = "False";
1.2 raeburn 3482: }
1.15 raeburn 3483: $output .= "\><startouttext />".$$settings{$id}{$$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
3484: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.2 raeburn 3485: }
1.11 raeburn 3486: if ($context eq 'CSTR') {
3487: chomp($output);
3488: $output .= qq|
1.2 raeburn 3489: </foilgroup>
3490: </optionresponse>
3491: |;
1.11 raeburn 3492: }
1.2 raeburn 3493: } elsif ($$settings{$id}{class} eq 'QUESTION_ORDER') {
1.15 raeburn 3494: my $numfoils = @{$$allanswers{$id}};
1.12 raeburn 3495: my @allorder = ();
1.11 raeburn 3496: if ($context eq 'CSTR') {
3497: $output .= qq|
1.2 raeburn 3498: <rankresponse max="$numfoils" randomize="yes">
3499: <foilgroup>
3500: |;
1.12 raeburn 3501: } else {
3502: $resourcedata{$symb.'newopt'} = '';
3503: $resourcedata{$symb.'delopt'} = '';
3504: $resourcedata{$symb.'hiddenparts'} = '!option';
3505: $resourcedata{$symb.'questiontype'} = 'option';
3506: $resourcedata{$symb.'maxfoils'} = $numfoils;
1.11 raeburn 3507: }
1.15 raeburn 3508: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
1.11 raeburn 3509: if ($context eq 'CSTR') {
1.15 raeburn 3510: $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$$allanswers{$id}[$k]}{order}."\"><startouttext />".$$settings{$id}{$$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
1.12 raeburn 3511: } else {
3512: my $iter = $k+1;
1.15 raeburn 3513: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
3514: if (!grep/^$$settings{$id}{$$allanswers{$id}[$k]}{order}$/,@allorder) {
3515: push @allorder, $$settings{$id}{$$allanswers{$id}[$k]}{order};
1.12 raeburn 3516: }
1.11 raeburn 3517: }
1.2 raeburn 3518: }
1.11 raeburn 3519: if ($context eq 'CSTR') {
3520: chomp($output);
3521: $output .= qq|
1.2 raeburn 3522: </foilgroup>
3523: </rankresponse>
3524: |;
1.12 raeburn 3525: } else {
3526: @allorder = sort {$a <=> $b} @allorder;
3527: $resourcedata{$symb.'options'} = "('".join("','",@allorder)."')";
1.11 raeburn 3528: }
1.2 raeburn 3529: } elsif ($$settings{$id}{class} eq 'QUESTION_FILLINBLANK') {
3530: my $numerical = 1;
1.11 raeburn 3531: if ($context eq 'DOCS') {
3532: $numerical = 0;
3533: } else {
1.15 raeburn 3534: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
3535: if ($$settings{$id}{$$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) {
1.11 raeburn 3536: $numerical = 0;
3537: }
1.2 raeburn 3538: }
3539: }
3540: if ($numerical) {
3541: my $numans;
3542: my $tol;
1.15 raeburn 3543: if (@{$$allanswers{$id}} == 1) {
1.2 raeburn 3544: $tol = 5;
1.15 raeburn 3545: $numans = $$settings{$id}{$$allanswers{$id}[0]}{text};
1.2 raeburn 3546: } else {
1.15 raeburn 3547: my $min = $$settings{$id}{$$allanswers{$id}[0]}{text};
3548: my $max = $$settings{$id}{$$allanswers{$id}[0]}{text};
3549: for (my $k=1; $k<@{$$allanswers{$id}}; $k++) {
3550: if ($$settings{$id}{$$allanswers{$id}[$k]}{text} <= $min) {
3551: $min = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.2 raeburn 3552: }
1.15 raeburn 3553: if ($$settings{$id}{$$allanswers{$id}[$k]}{text} >= $max) {
3554: $max = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.2 raeburn 3555: }
3556: }
3557: $numans = ($max + $min)/2;
3558: $tol = 100*($max - $min)/($numans*2);
3559: }
1.11 raeburn 3560: if ($context eq 'CSTR') {
3561: $output .= qq|
1.2 raeburn 3562: <numericalresponse answer="$numans">
3563: <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
3564: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures"
3565: />
3566: <textline />
3567: </numericalresponse>
3568: |;
1.11 raeburn 3569: }
1.2 raeburn 3570: } else {
1.12 raeburn 3571: if ($context eq 'DOCS') {
3572: $resourcedata{$symb.'hiddenparts'} = '!string';
3573: $resourcedata{$symb.'questiontype'} = 'string';
1.15 raeburn 3574: $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}};
1.12 raeburn 3575: $resourcedata{$symb.'hiddenparts'} = '!string';
3576: $resourcedata{$symb.'stringtype'} = 'ci';
1.15 raeburn 3577: $resourcedata{$symb.'stringanswer'} = $$settings{$id}{$$allanswers{$id}[0]}{text};
1.12 raeburn 3578: } else {
1.15 raeburn 3579: if (@{$$allanswers{$id}} == 1) {
1.11 raeburn 3580: $output .= qq|
1.15 raeburn 3581: <stringresponse answer="$$settings{$id}{$$allanswers{$id}[0]}{text}" type="ci">
1.2 raeburn 3582: <textline>
3583: </textline>
3584: </stringresponse>
3585: |;
1.11 raeburn 3586: } else {
3587: my @answertext = ();
1.15 raeburn 3588: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
3589: $$settings{$id}{$$allanswers{$id}[$k]}{text} =~ s/\|/\|/g;
3590: push @answertext, $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.11 raeburn 3591: }
3592: my $regexpans = join('|',@answertext);
3593: $regexpans = '/^('.$regexpans.')\b/';
3594: $output .= qq|
1.2 raeburn 3595: <stringresponse answer="$regexpans" type="re">
3596: <textline>
3597: </textline>
3598: </stringresponse>
3599: |;
1.11 raeburn 3600: }
3601: }
1.2 raeburn 3602: }
3603: } elsif ($$settings{$id}{class} eq "QUESTION_MATCH") {
1.12 raeburn 3604: my @allmatchers = ();
3605: my %matchtext = ();
1.11 raeburn 3606: if ($context eq 'CSTR') {
3607: $output .= qq|
1.2 raeburn 3608: <matchresponse max="10" randomize="yes">
3609: <foilgroup>
3610: <itemgroup>
3611: |;
1.12 raeburn 3612: } else {
3613: $resourcedata{$symb.'newopt'} = '';
3614: $resourcedata{$symb.'delopt'} = '';
3615: $resourcedata{$symb.'hiddenparts'} = '!option';
3616: $resourcedata{$symb.'questiontype'} = 'option';
1.15 raeburn 3617: $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}};
1.11 raeburn 3618: }
1.15 raeburn 3619: for (my $k=0; $k<@{$$allchoices{$id}}; $k++) {
1.11 raeburn 3620: if ($context eq 'CSTR') {
3621: $output .= qq|
1.15 raeburn 3622: <item name="$$allchoices{$id}[$k]">
3623: <startouttext />$$settings{$id}{$$allchoices{$id}[$k]}{text}<endouttext />
1.2 raeburn 3624: </item>
3625: |;
1.12 raeburn 3626: } else {
1.15 raeburn 3627: if (!grep/^$$settings{$id}{$$allchoices{$id}[$k]}{text}$/,@allmatchers) {
3628: push @allmatchers, $$settings{$id}{$$allchoices{$id}[$k]}{text};
3629: $matchtext{$$allchoices{$id}[$k]} = $$settings{$id}{$$allchoices{$id}[$k]}{text};
1.12 raeburn 3630: }
1.11 raeburn 3631: }
1.2 raeburn 3632: }
1.11 raeburn 3633: if ($context eq 'CSTR') {
3634: $output .= qq|
1.2 raeburn 3635: </itemgroup>
3636: |;
1.11 raeburn 3637: }
1.15 raeburn 3638: for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
1.11 raeburn 3639: if ($context eq 'CSTR') {
3640: $output .= qq|
1.15 raeburn 3641: <foil location="random" value="$$settings{$id}{$$allanswers{$id}[$k]}{choice_id}" name="$$allanswers{$id}[$k]">
3642: <startouttext />$$settings{$id}{$$allanswers{$id}[$k]}{text}<endouttext />
1.2 raeburn 3643: </foil>
3644: |;
1.12 raeburn 3645: } else {
3646: my $iter = $k+1;
1.15 raeburn 3647: $resourcedata{$symb.'value'.$iter} = $matchtext{$$settings{$id}{$$allanswers{$id}[$k]}{choice_id}};
3648: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
1.11 raeburn 3649: }
1.2 raeburn 3650: }
1.11 raeburn 3651: if ($context eq 'CSTR') {
3652: $output .= qq|
1.2 raeburn 3653: </foilgroup>
3654: </matchresponse>
3655: |;
1.12 raeburn 3656: } else {
3657: $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')";
1.11 raeburn 3658: }
1.2 raeburn 3659: }
3660: }
1.11 raeburn 3661: if ($context eq 'CSTR') {
3662: $output .= qq|</problem>
1.2 raeburn 3663: |;
1.20 raeburn 3664: my $title = $$settings{title};
3665: $title =~ s/\s/_/g;
3666: $title =~ s/\W//g;
3667: $title .= '_'.$id;
3668: open(PROB,">:utf8", "$newdir/$title.problem");
1.11 raeburn 3669: print PROB $output;
3670: close PROB;
1.12 raeburn 3671: } else {
3672: # put %resourcedata;
3673: my $reply=&Apache::lonnet::cput
3674: ('resourcedata',\%resourcedata,$cdom,$cnum);
1.11 raeburn 3675: }
1.2 raeburn 3676: }
3677: }
3678:
1.15 raeburn 3679: sub write_webct4_questions {
1.35 ! raeburn 3680: my ($cms,$alldbquestids,$context,$settings,$dirname,$allanswers,$allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo) = @_;
1.16 raeburn 3681: my $qnum = 0;
3682: foreach my $id (@{$alldbquestids}) {
3683: $qnum ++;
3684: my $output;
3685: my $permcontainer = $destdir.'/sequences/'.$id.'.sequence';
3686: my $allfeedback;
3687: my $questionimage;
3688: foreach my $fdbk (@{$$settings{$id}{feedback}}) {
3689: my $feedback = $$settings{$id}{$fdbk}{text};
3690: if ($$settings{$id}{$fdbk}{texttype} eq 'text/html') {
3691: $feedback = &HTML::Entities::decode($feedback);
3692: }
3693: $allfeedback .= $feedback;
3694: }
3695: if ($$settings{$id}{texttype} eq 'text/html') {
1.35 ! raeburn 3696: if ($$settings{$id}{text}) {
! 3697: $$settings{$id}{text} = &text_cleanup($$settings{$id}{text});
! 3698: }
! 3699: }
1.16 raeburn 3700: if ($$settings{$id}{class} eq 'numerical') {
3701: foreach my $numid (@{$$settings{$id}{numids}}) {
3702: foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) {
1.35 ! raeburn 3703: if ($cms eq 'webct4ce') {
! 3704: $$settings{$id}{text} =~ s/{($var)}/\$$1 /g;
! 3705: } elsif ($cms eq 'webctvista4') {
! 3706: $$settings{$id}{text} =~ s/\[($var)\]/\$$1 /g;
! 3707: }
1.16 raeburn 3708: }
3709: }
3710: }
3711: $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
3712: my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
3713: my %resourcedata = ();
3714: for (my $i=0; $i<10; $i++) {
3715: my $iter = $i+1;
3716: $resourcedata{$symb.'text'.$iter} = "";
3717: $resourcedata{$symb.'value'.$iter} = "unused";
3718: $resourcedata{$symb.'position'.$iter} = "random";
3719: }
3720: $resourcedata{$symb.'randomize'} = 'yes';
3721: $resourcedata{$symb.'maxfoils'} = 10;
3722: if ($context eq 'CSTR') {
1.22 raeburn 3723: unless ($$settings{$id}{class} eq 'numerical') {
3724: $output = qq|<problem>
1.16 raeburn 3725: |;
1.22 raeburn 3726: }
1.16 raeburn 3727: }
3728: $$total{prob} ++;
3729: if (exists($$settings{$id}{uri})) {
1.35 ! raeburn 3730: if ($cms eq 'webct4ce') {
! 3731: if ($$settings{$id}{imagtype} =~ /^image\//) {
! 3732: $questionimage = '<p><img src="../../resfiles/'.$$settings{$id}{uri}.'" /></p>'."\n";
! 3733: } else {
! 3734: $questionimage = '<p><img src="../../resfiles/'.$$settings{$id}{uri}.'" /></p>'."\n";
! 3735: }
! 3736: } elsif ($cms eq 'webctvista4') {
! 3737: if ($$settings{$id}{uri} =~ /(gif|jpg|png)$/i) {
! 3738: $questionimage = '<p><img src="../../resfiles/'.$$settings{$id}{uri}.'" /></p>'."\n";
! 3739: $questionimage =~ s#(//+)#/#g;
! 3740: } else {
! 3741: $questionimage = '<a href="'.$$settings{$id}{uri}.'" target="exturi" >'.$$settings{$id}{uri}.'</a>';
! 3742: }
1.16 raeburn 3743: }
3744: }
3745: if ($$settings{$id}{class} eq "paragraph") {
1.35 ! raeburn 3746: my $pre_fill_answer = $$settings{$id}{PARA}{PARA}{PRE_FILL_ANSWER};
1.16 raeburn 3747: if ($context eq 'CSTR') {
3748: $output .= qq|<startouttext /><p>$$settings{$id}{text}</p>$questionimage<endouttext />
3749: <essayresponse>
1.35 ! raeburn 3750: <textfield>$pre_fill_answer</textfield>
1.16 raeburn 3751: </essayresponse>
3752: <postanswerdate>
3753: $allfeedback
3754: </postanswerdate>
3755: |;
3756: } else {
3757: $resourcedata{$symb.'questiontext'} = '<p>'.$$settings{$id}{text}.'</p>'.$questionimage;
3758: $resourcedata{$symb.'hiddenparts'} = '!essay';
3759: $resourcedata{$symb.'questiontype'} = 'essay';
3760: }
3761: } else {
3762: if ($context eq 'CSTR') {
3763: $output .= qq|<startouttext /><p>$$settings{$id}{text}</p>$questionimage<endouttext />\n|;
3764: } else {
3765: $resourcedata{$symb.'questiontext'} = '<p>'.$$settings{$id}{text}.'</p>'.$questionimage;
3766: }
3767: if ($$settings{$id}{class} eq 'multiplechoice') {
3768: foreach my $list (@{$$settings{$id}{lists}}) {
3769: my $numfoils = @{$$allanswers{$id}{$list}};
3770: if ($$settings{$id}{$list}{rcardinality} eq 'Single') {
3771: if ($context eq 'CSTR') {
3772: $output .= qq|
3773: <radiobuttonresponse max="$numfoils" randomize="$$settings{$id}{$list}{randomize}">
3774: <foilgroup>
3775: |;
3776: } else {
3777: $resourcedata{$symb.'hiddenparts'} = '!radio';
3778: $resourcedata{$symb.'questiontype'} = 'radio';
3779: $resourcedata{$symb.'maxfoils'} = $numfoils;
3780: }
3781: for (my $k=0; $k<@{$$allanswers{$id}{$list}}; $k++) {
3782: my $iter = $k+1;
3783: $output .= " <foil name=\"foil".$k."\" value=\"";
3784: if (grep/^$$allanswers{$id}{$list}[$k]$/,@{$$settings{$id}{$list}{correctanswer}}) {
3785: $output .= "true\" location=\"";
3786: $resourcedata{$symb.'value'.$iter} = "true";
3787: } else {
3788: $output .= "false\" location=\"";
3789: $resourcedata{$symb.'value'.$iter} = "false";
3790: }
3791: if (lc ($$allanswers{$id}{$list}[$k]) =~ m/^\s?([Aa]ll)|([Nn]one)\s(of\s)?the\sabove\.?/) {
3792: $output .= "bottom\"";
3793: $resourcedata{$symb.'position'.$iter} = "bottom";
3794: } else {
3795: $output .= "random\"";
3796: }
3797: if ($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{texttype} eq 'text/html') {
3798: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text});
1.21 www 3799: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text});
1.16 raeburn 3800: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi;
3801: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g;
3802:
3803: }
3804: $output .= "\><startouttext />".$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
3805: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
3806: $output .= '<endouttext /></foil>'."\n";
3807: }
3808: if ($context eq 'CSTR') {
3809: chomp($output);
3810: $output .= qq|
3811: </foilgroup>
3812: </radiobuttonresponse>
3813: |;
3814: }
3815: } else {
3816: if ($context eq 'CSTR') {
3817: $output .= qq|
3818: <optionresponse max="$numfoils" randomize="yes">
3819: <foilgroup options="('True','False')">
3820: |;
3821: } else {
3822: $resourcedata{$symb.'newopt'} = '';
3823: $resourcedata{$symb.'delopt'} = '';
3824: $resourcedata{$symb.'options'} = "('True','False')";
3825: $resourcedata{$symb.'hiddenparts'} = '!option';
3826: $resourcedata{$symb.'questiontype'} = 'option';
3827: $resourcedata{$symb.'maxfoils'} = $numfoils;
3828: }
3829: for (my $k=0; $k<@{$$allanswers{$id}{$list}}; $k++) {
3830: my $iter = $k+1;
3831: $output .= " <foil name=\"foil".$k."\" value=\"";
3832: if (grep/^$$allanswers{$id}{$list}[$k]$/,@{$$settings{$id}{$list}{correctanswer}}) {
3833: $output .= "True\"";
3834: $resourcedata{$symb.'value'.$iter} = "True";
3835: } else {
3836: $output .= "False\"";
3837: $resourcedata{$symb.'value'.$iter} = "False";
3838: }
3839: if ($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{texttype} eq 'text/html') {
3840: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text});
1.21 www 3841: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text});
1.16 raeburn 3842:
3843: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi;
3844: $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g;
3845: }
3846: $output .= "\><startouttext />".$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}."<br /><endouttext /></foil>\n";
3847: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
3848: }
3849: if ($context eq 'CSTR') {
3850: chomp($output);
3851: $output .= qq|
3852: </foilgroup>
3853: </optionresponse>
3854: |;
3855: }
3856: }
3857: }
3858: } elsif ($$settings{$id}{class} eq 'match') {
3859: my %allmatchers = ();
3860: my @allmatch = ();
3861: my %matchtext = ();
3862: my $anscount = 0;
3863: my %ansnum = ();
3864: my $maxfoils = 0;
3865: my $test_for_html = 0;
3866: foreach my $grp (@{$$allchoices{$id}}) {
3867: $maxfoils += @{$$settings{$id}{$grp}{correctanswer}};
3868: foreach my $answer_id (@{$$allanswers{$id}{$grp}}) {
3869: if ($$settings{$id}{$grp}{$answer_id}{texttype} eq '/text/html') {
3870:
3871: $$settings{$id}{$grp}{$answer_id}{text} = &HTML::Entities::decode($$settings{$id}{$grp}{$answer_id}{text});
3872: $test_for_html = &test_for_html($$settings{$id}{$grp}{$answer_id}{text});
1.21 www 3873: $$settings{$id}{$grp}{$answer_id}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$grp}{$answer_id}{text});
1.16 raeburn 3874: $$settings{$id}{$grp}{$answer_id}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi;
3875: $$settings{$id}{$grp}{$answer_id}{text} =~ s#</?p>##g;
3876: }
3877: unless (exists($allmatchers{$$settings{$id}{$grp}{$answer_id}{text}})) {
3878: $allmatchers{$$settings{$id}{$grp}{$answer_id}{text}} = $anscount;
3879: $allmatch[$anscount] = $$settings{$id}{$grp}{$answer_id}{text};
3880: $anscount ++;
3881:
3882: }
3883: if (grep/^$answer_id$/,@{$$settings{$id}{$grp}{correctanswer}}) {
3884: push(@{$ansnum{$grp}},$allmatchers{$$settings{$id}{$grp}{$answer_id}{text}});
3885: }
3886: }
3887: if ($context eq 'DOCS') {
3888: $matchtext{$ansnum{$grp}[0]} = $allmatch[$ansnum{$grp}[0]-1];
3889: }
3890: }
3891: my $allmatchlist = "('".join("','",@allmatch)."')";
3892: if ($context eq 'CSTR') {
3893: if ($test_for_html) {
3894: $output .= qq|
3895: <matchresponse max="$maxfoils" randomize="yes">
3896: <foilgroup>
3897: <itemgroup>
3898: |;
3899: } else {
3900: $output .= qq|
3901: <optionresponse max="10" randomize="yes">
1.25 raeburn 3902: <foilgroup options="$allmatchlist">
1.16 raeburn 3903: |;
3904: }
3905: } else {
3906: $resourcedata{$symb.'newopt'} = '';
3907: $resourcedata{$symb.'delopt'} = '';
3908: $resourcedata{$symb.'hiddenparts'} = '!option';
3909: $resourcedata{$symb.'questiontype'} = 'option';
3910: $resourcedata{$symb.'maxfoils'} = $maxfoils;
3911: }
3912: my $iter = 0;
3913: foreach my $match (@allmatch) {
3914: $iter ++;
3915: if ($context eq 'CSTR') {
3916: if ($test_for_html) {
3917: $output .= qq|
3918: <item name="ans_$iter">
3919: <startouttext />$match<endouttext />
3920: </item>
3921: |;
3922: }
3923: }
3924: }
3925: if ($context eq 'CSTR') {
3926: if ($test_for_html) {
3927: $output .= qq|
3928: </itemgroup>
3929: |;
3930: }
3931: }
3932: $iter = 0;
3933: for (my $k=0; $k<@{$$allchoices{$id}}; $k++) {
3934: if ($$settings{$id}{$$allchoices{$id}[$k]}{texttype} eq 'text/html') {
3935: $$settings{$id}{$$allchoices{$id}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$$allchoices{$id}[$k]}{text});
1.21 www 3936: $$settings{$id}{$$allchoices{$id}[$k]}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$$allchoices{$id}[$k]}{text});
1.16 raeburn 3937: $$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi;
3938: $$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#</?p>##g;
3939: }
3940: foreach my $ans (@{$ansnum{$$allchoices{$id}[$k]}}) {
3941: $iter ++;
3942: my $ans_id = $ans + 1;
3943: if ($context eq 'CSTR') {
3944: my $value;
3945: if ($test_for_html) {
3946: $value = 'ans_'.$ans_id;
3947: } else {
3948: $value = $allmatch[$ans];
3949: }
3950: $output .= qq|
3951: <foil location="random" value="$value" name="foil_$iter">
3952: <startouttext />$$settings{$id}{$$allchoices{$id}[$k]}{text}<endouttext />
3953: </foil>
3954:
3955: |;
3956: }
3957: }
3958: if ($context eq 'DOCS') {
3959: $resourcedata{$symb.'value'.$iter} = $matchtext{$ansnum{$$allchoices{$id}[$k]}[0]};
3960: $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allchoices{$id}[0]}{text};
3961: }
3962: }
3963: if ($context eq 'CSTR') {
3964: $output .= qq|
3965: </foilgroup>
3966: |;
3967: if ($test_for_html) {
3968: $output .= qq|
3969: </matchresponse>
3970: |;
3971: } else {
3972: $output .= qq|
3973: </optionresponse>
3974: |;
3975: }
3976: } else {
3977: $resourcedata{$symb.'options'} = "('".join("','",@allmatch)."')";
3978: }
1.35 ! raeburn 3979: } elsif (($$settings{$id}{class} eq 'string') ||
! 3980: ($$settings{$id}{class} eq 'shortanswer')) {
1.16 raeburn 3981: my $labelnum = 0;
1.35 ! raeburn 3982: my @str_labels = ();
! 3983: if ($cms eq 'webct4ce') {
! 3984: foreach my $str_id (@{$$settings{$id}{str}}) {
! 3985: foreach my $label (@{$$settings{$id}{$str_id}{labels}}) {
! 3986: push(@str_labels,$label);
! 3987: }
! 3988: }
! 3989: } elsif ($cms eq 'webctvista4') {
! 3990: @str_labels = @{$$settings{$id}{str}};
! 3991: }
! 3992: foreach my $label (@str_labels) {
! 3993: $labelnum ++;
! 3994: my $numerical = 1;
! 3995: if ($context eq 'DOCS') {
! 3996: $numerical = 0;
! 3997: } else {
! 3998: for (my $i=0; $i<@{$$settings{$id}{strings}{$label}}; $i++) {
! 3999: $$settings{$id}{strings}{$label}[$i] =~ s/^\s+//;
! 4000: $$settings{$id}{strings}{$label}[$i] =~ s/\s+$//;
! 4001: if ($$settings{$id}{strings}{$label}[$i] =~ m/([^\-\d\.]|\.\.)/) {
! 4002: $numerical = 0;
! 4003: }
! 4004: }
! 4005: }
! 4006: if ($numerical) {
! 4007: my $numans;
! 4008: my $tol;
! 4009: if (@{$$settings{$id}{strings}{$label}} == 1) {
! 4010: $tol = '5%';
! 4011: $numans = $$settings{$id}{strings}{$label}[0];
1.16 raeburn 4012: } else {
1.35 ! raeburn 4013: my $min = $$settings{$id}{strings}{$label}[0];
! 4014: my $max = $$settings{$id}{strings}{$label}[0];
! 4015: for (my $k=1; $k<@{$$settings{$id}{strings}{$label}}; $k++) {
! 4016: if ($$settings{$id}{strings}{$label}[$k] <= $min) {
! 4017: $min = $$settings{$id}{strings}{$label}[$k];
! 4018: }
! 4019: if ($$settings{$id}{strings}{$label}[$k] >= $max) {
! 4020: $max = $$settings{$id}{strings}{$label}[$k];
1.16 raeburn 4021: }
4022: }
1.35 ! raeburn 4023: $numans = ($max + $min)/2;
! 4024: if ($numans == 0) {
! 4025: my $dev = abs($max - $numans);
! 4026: if (abs($numans - $min) > $dev) {
! 4027: $dev = abs($numans - $min);
! 4028: }
! 4029: $tol = $dev;
1.16 raeburn 4030: } else {
1.35 ! raeburn 4031: $tol = 100*($max - $min)/($numans*2);
! 4032: $tol .= '%';
1.16 raeburn 4033: }
1.35 ! raeburn 4034: }
! 4035: if ($context eq 'CSTR') {
! 4036: if (@{$$settings{$id}{str}} > 1) {
! 4037: $output .= qq|
1.16 raeburn 4038: <startouttext />$labelnum.<endouttext />
4039: |;
1.35 ! raeburn 4040: }
! 4041: $output .= qq|
1.16 raeburn 4042: <numericalresponse answer="$numans">
4043: <responseparam type="tolerance" default="$tol" name="tol" description="Numerical Tolerance" />
4044: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures"
4045: />
4046: <textline />
4047: </numericalresponse>
4048: <startouttext /><br /><endouttext />
4049: |;
1.35 ! raeburn 4050: }
! 4051: } else {
! 4052: if ($context eq 'DOCS') {
! 4053: $resourcedata{$symb.'hiddenparts'} = '!string';
! 4054: $resourcedata{$symb.'questiontype'} = 'string';
! 4055: $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}{strings}{$label}};
! 4056: $resourcedata{$symb.'hiddenparts'} = '!string';
! 4057: if ($$settings{$id}{$label}{case} eq "No") {
! 4058: $resourcedata{$symb.'stringtype'} = 'ci';
! 4059: } elsif ($$settings{$id}{$label}{case} eq "Yes") {
! 4060: $resourcedata{$symb.'stringtype'} = 'cs';
1.16 raeburn 4061: }
1.35 ! raeburn 4062: $resourcedata{$symb.'stringanswer'} = $$settings{$id}{strings}{$label}[0];
1.16 raeburn 4063: } else {
1.35 ! raeburn 4064: if (@{$$settings{$id}{str}} > 1) {
! 4065: $output .= qq|
! 4066: <startouttext />$labelnum.<endouttext />
! 4067: |;
! 4068: }
! 4069: if (@{$$settings{$id}{strings}{$label}} == 1) {
! 4070: my $casetype;
1.16 raeburn 4071: if ($$settings{$id}{$label}{case} eq "No") {
1.35 ! raeburn 4072: $casetype = 'ci';
1.16 raeburn 4073: } elsif ($$settings{$id}{$label}{case} eq "Yes") {
1.35 ! raeburn 4074: $casetype = 'cs';
1.16 raeburn 4075: }
1.35 ! raeburn 4076: $output .= qq|
1.16 raeburn 4077: <stringresponse answer="$$settings{$id}{strings}{$label}[0]" type="$casetype">
4078: <textline>
4079: </textline>
4080: </stringresponse>
4081: <startouttext /><br /><endouttext />
4082: |;
1.35 ! raeburn 4083: } else {
! 4084: my @answertext = ();
! 4085: for (my $k=0; $k<@{$$settings{$id}{strings}{$label}}; $k++) {
! 4086: $$settings{$id}{strings}{$label}[$k] =~ s/\|/\|/g;
! 4087: push @answertext, $$settings{$id}{strings}{$label}[$k];
! 4088: }
! 4089: my $regexpans = join('|',@answertext);
! 4090: $regexpans = '/^('.$regexpans.')\b/';
! 4091: $output .= qq|
1.16 raeburn 4092: <stringresponse answer="$regexpans" type="re">
4093: <textline>
4094: </textline>
4095: </stringresponse>
4096: <startouttext /><br /><endouttext />
4097: |;
4098: }
4099: }
4100: }
4101: }
4102: } elsif ($$settings{$id}{class} eq 'numerical') {
1.24 raeburn 4103: my %mathfns = (
4104: 'abs' => 'abs',
4105: 'acos' => 'acos',
4106: 'asin' => 'asin',
4107: 'atan' => 'atan',
4108: 'ceil' => 'ceil',
4109: 'cos' => 'cos',
4110: 'exp' => 'exp',
4111: 'fact' => 'factorial',
4112: 'floor' => 'floor',
4113: 'int' => 'int',
4114: 'ln' => 'log',
4115: 'log' => 'log',
4116: 'max' => 'max',
4117: 'min' => 'min',
4118: 'round' => 'roundto',
4119: 'sin' => 'sin',
4120: 'sqrt' => 'sqrt',
4121: 'tan' => 'tan',
4122: );
1.16 raeburn 4123: my $scriptblock = qq|
4124: <script type="loncapa/perl">
4125: |;
4126: foreach my $numid (@{$$settings{$id}{numids}}) {
4127: my $formula = $$settings{$id}{$numid}{formula};
1.24 raeburn 4128: my $pattern = join('|',(sort (keys (%mathfns))));
4129: $formula =~ s/($pattern)/\&$mathfns{$1}/g;
1.16 raeburn 4130: foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) {
4131: my $decnum = $$settings{$id}{$numid}{vars}{$var}{dec};
4132: my $increment = '0.';
4133: if ($decnum == 0) {
4134: $increment = 1;
4135: } else {
4136: my $deccount = $decnum;
4137: while ($deccount > 1) {
4138: $increment.= '0';
4139: $deccount --;
4140: }
4141: $increment .= '1';
1.35 ! raeburn 4142: }
! 4143: if ($cms eq 'webct4ce') {
! 4144: $formula =~ s/{($var)}/(\$$1)/g;
! 4145: } elsif ($cms eq 'webctvista4') {
! 4146: $formula =~ s/\[($var)\]/(\$$1)/g;
! 4147: }
1.16 raeburn 4148: $scriptblock .= qq|
4149: \$$var=&random($$settings{$id}{$numid}{vars}{$var}{min},$$settings{$id}{$numid}{vars}{$var}{max},$increment);
4150: |;
4151: }
4152: $scriptblock .= qq|
4153: \$answervar = $formula;
4154: </script>
4155: |;
4156: if ($context eq 'CSTR') {
1.22 raeburn 4157: $output = "<problem>\n".$scriptblock.$output;
1.16 raeburn 4158: my $ansformat = '';
4159: my $sigfig = '0,15';
4160: if ($$settings{$id}{$numid}{format} eq 'sig') {
4161: $sigfig = $$settings{$id}{$numid}{digits}.','.$$settings{$id}{$numid}{digits};
4162: } elsif ($$settings{$id}{$numid}{format} eq 'dec') {
4163: $ansformat = $$settings{$id}{$numid}{digits}.'f';
4164: }
4165: if ($ansformat) {
4166: $ansformat = 'format="'.$ansformat.'"';
4167: }
4168: my $tolerance = $$settings{$id}{$numid}{tolerance};
1.35 ! raeburn 4169: if (lc($$settings{$id}{$numid}{toltype}) eq 'percent') {
1.16 raeburn 4170: $tolerance .= '%';
4171: }
4172: my $unit = '';
4173: foreach my $unitid (@{$$settings{$id}{$numid}{units}}) {
4174: $unit .= $$settings{$id}{$numid}{$unitid}{text};
4175: }
4176: my $unitentry = '';
4177: if ($unit ne '') {
1.26 raeburn 4178: $unitentry = 'unit="'.$unit.'"';
1.16 raeburn 4179: }
4180: $output .= qq|
4181: <numericalresponse $unitentry $ansformat answer="\$answervar">
4182: <responseparam type="tolerance" default="$tolerance" name="tol" description="Numerical Tolerance" />
4183: <responseparam name="sig" type="int_range" default="$sigfig" description="Significant Figures"
4184: />
4185: <textline />
4186: </numericalresponse>
4187: |;
4188: }
4189: }
4190: }
4191: }
4192: if ($context eq 'CSTR') {
4193: my $catid = $$settings{$id}{category};
4194: my $probdir = $$catinfo{$catid}{title}.'_'.$catid;
4195: $probdir =~ s/\s/_/g;
4196: $probdir =~ s/\W//g;
4197: if (!-e "$destdir/problems/$probdir") {
4198: mkdir("$destdir/problems/$probdir",0755);
4199: }
4200: $output .= qq|</problem>
4201: |;
4202: my $title = $$settings{$id}{title};
4203: $title =~ s/\s/_/g;
4204: $title =~ s/\W//g;
4205: $title .= '_'.$id;
4206: open(PROB,">:utf8", "$destdir/problems/$probdir/$title.problem");
4207: print PROB $output;
4208: close PROB;
4209: } else {
4210: # put %resourcedata;
4211: my $reply=&Apache::lonnet::cput
4212: ('resourcedata',\%resourcedata,$cdom,$cnum);
4213: }
4214: }
1.15 raeburn 4215: }
4216:
1.35 ! raeburn 4217: sub text_cleanup {
! 4218: my ($text) = @_;
! 4219: $text =~ s/(\&)(nbsp|gt|lt)(?!;)/$1$2;$3/gi;
! 4220: $text = &Apache::loncleanup::htmlclean($text);
! 4221: $text =~ s#(<img src=["']?)([^>]+?)(/?>)#$1../../resfiles/$2 />#gi;
! 4222: $text =~ s#<([bh])r>#<$1r />#g;
! 4223: $text =~ s#<p>#<br /><br />#g;
! 4224: $text =~ s#</p>##g;
! 4225: return $text;
! 4226: }
! 4227:
1.16 raeburn 4228: sub test_for_html {
4229: my ($source) = @_;
4230: my @tags = ();
4231: my $p = HTML::Parser->new
4232: (
4233: xml_mode => 1,
4234: start_h =>
4235: [sub {
4236: my ($tagname) = @_;
4237: push @tags, $tagname;
4238: }, "tagname"],
4239: );
4240: $p->parse($source);
4241: $p->eof;
4242: return length(@tags);
4243: }
4244:
1.15 raeburn 4245: sub write_bb6_questions {
1.30 raeburn 4246: my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
4247: my $qnum = 0;
4248: foreach my $id (@{$allids}) {
4249: my $questiontext = $$settings{$id}{question}{text};
4250: my $question_texttype = $$settings{$id}{question}{texttype};
4251: &process_html(\$questiontext,'bb6',$question_texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
4252: $qnum ++;
4253: my $output;
4254: my $permcontainer = $containerdir;
4255: $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
4256: my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
4257: my %resourcedata = ();
4258: for (my $i=0; $i<10; $i++) {
4259: my $iter = $i+1;
4260: $resourcedata{$symb.'text'.$iter} = "";
4261: $resourcedata{$symb.'value'.$iter} = "unused";
4262: $resourcedata{$symb.'position'.$iter} = "random";
4263: }
4264: $resourcedata{$symb.'randomize'} = 'yes';
4265: $resourcedata{$symb.'maxfoils'} = 10;
4266: if ($context eq 'CSTR') {
4267: $output = qq|<problem>
4268: |;
4269: }
4270: $$total{prob} ++;
1.33 raeburn 4271: $questiontext .= &add_images_links('question',$context,$settings,$id,$dirname,$res);
1.30 raeburn 4272: if ($$settings{$id}{class} eq "Essay") {
4273: if ($context eq 'CSTR') {
4274: $output .= qq|<startouttext />$questiontext<endouttext />
4275: <essayresponse>
4276: <textfield></textfield>
4277: </essayresponse>
4278: |;
4279: } else {
4280: $resourcedata{$symb.'questiontext'} = $questiontext;
4281: $resourcedata{$symb.'hiddenparts'} = '!essay';
4282: $resourcedata{$symb.'questiontype'} = 'essay';
4283: }
4284: } else {
4285: if ($context eq 'CSTR') {
4286: $output .= qq|<startouttext />$questiontext\n<endouttext />|;
4287: } else {
4288: $resourcedata{$symb.'questiontext'} = $questiontext;
4289: }
4290: my $numfoils = @{$$settings{$id}{answers}};
4291: if (($$settings{$id}{class} eq 'Multiple Choice') ||
4292: ($$settings{$id}{class} eq 'True/False')) {
4293: if ($context eq 'CSTR') {
4294: $output .= qq|
4295: <radiobuttonresponse max="$numfoils" randomize="yes">
4296: <foilgroup>
4297: |;
4298: } else {
4299: $resourcedata{$symb.'hiddenparts'} = '!radio';
4300: $resourcedata{$symb.'questiontype'} = 'radio';
4301: $resourcedata{$symb.'maxfoils'} = $numfoils;
4302: }
4303: for (my $k=0; $k<$numfoils; $k++) {
4304: my $iter = $k+1;
4305: my $answer_id = $$settings{$id}{answers}[$k];
4306: my $answer_text = $$settings{$id}{$answer_id}{text};
4307: my $texttype = $$settings{$id}{$answer_id}{texttype};
4308: &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
1.33 raeburn 4309: $answer_text .= &add_images_links('response',$context,$settings,$id,$dirname,$res);
1.30 raeburn 4310: $output .= " <foil name=\"foil".$k."\" value=\"";
4311: if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) {
4312: $output .= "true\" location=\"";
4313: $resourcedata{$symb.'value'.$iter} = "true";
4314: } else {
4315: $output .= "false\" location=\"";
4316: $resourcedata{$symb.'value'.$iter} = "false";
4317: }
4318: if (lc ($$settings{$id}{$answer_id}{text}) =~ m/^\s?([Aa]ll)|([Nn]one)\s(of\s)?the\sabove\.?/) {
4319: $output .= "bottom\"";
4320: $resourcedata{$symb.'position'.$iter} = "bottom";
4321: } else {
4322: $output .= "random\"";
4323: }
4324: $output .= '\><startouttext />'.$answer_text.
4325: '<endouttext /></foil>'."\n";
4326: $resourcedata{$symb.'text'.$iter} = $answer_text;
4327: }
4328: if ($context eq 'CSTR') {
4329: chomp($output);
4330: $output .= qq|
4331: </foilgroup>
4332: <hintgroup showoncorrect="no">
4333: <radiobuttonhint>
4334: </radiobuttonhint>
4335: <hintpart on="default">
4336: <startouttext/><endouttext />
4337: </hintpart>
4338: </hintgroup>
4339: </radiobuttonresponse>
4340: |;
4341: }
4342: } elsif ($$settings{$id}{class} eq 'Multiple Answer') {
4343: if ($context eq 'CSTR') {
4344: $output .= qq|
4345: <optionresponse max="$numfoils" randomize="yes">
4346: <foilgroup options="('True','False')">
4347: |;
4348: } else {
4349: $resourcedata{$symb.'newopt'} = '';
4350: $resourcedata{$symb.'delopt'} = '';
4351: $resourcedata{$symb.'options'} = "('True','False')";
4352: $resourcedata{$symb.'hiddenparts'} = '!option';
4353: $resourcedata{$symb.'questiontype'} = 'option';
4354: $resourcedata{$symb.'maxfoils'} = $numfoils;
4355: }
4356: for (my $k=0; $k<$numfoils; $k++) {
4357: my $iter = $k+1;
4358: my $answer_id = $$settings{$id}{answers}[$k];
4359: my $answer_text = $$settings{$id}{$answer_id}{text};
4360: my $texttype = $$settings{$id}{$answer_id}{texttype};
4361: &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
1.33 raeburn 4362: $answer_text .= &add_images_links('response',$context,$settings,$id,$dirname,$res);
1.30 raeburn 4363:
4364: $output .= " <foil name=\"foil".$k."\" value=\"";
4365: if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) {
4366: $output .= "True\"";
4367: $resourcedata{$symb.'value'.$iter} = "True";
4368: } else {
4369: $output .= "False\"";
4370: $resourcedata{$symb.'value'.$iter} = "False";
4371: }
4372: $output .= "\><startouttext />".$answer_text."<endouttext /></foil>\n";
4373: $resourcedata{$symb.'text'.$iter} = $answer_text;
4374: }
4375: if ($context eq 'CSTR') {
4376: chomp($output);
4377: $output .= qq|
4378: </foilgroup>
4379: <hintgroup showoncorrect="no">
4380: <optionhint>
4381: </optionhint>
4382: <hintpart on="default">
4383: <startouttext/><endouttext />
4384: </hintpart>
4385: </hintgroup>
4386: </optionresponse>
4387: |;
4388: }
4389: } elsif ($$settings{$id}{class} eq 'Ordering') {
4390: my @allorder = ();
4391: if ($context eq 'CSTR') {
4392: $output .= qq|
4393: <rankresponse max="$numfoils" randomize="yes">
4394: <foilgroup>
4395: |;
4396: } else {
4397: $resourcedata{$symb.'newopt'} = '';
4398: $resourcedata{$symb.'delopt'} = '';
4399: $resourcedata{$symb.'hiddenparts'} = '!option';
4400: $resourcedata{$symb.'questiontype'} = 'option';
4401: $resourcedata{$symb.'maxfoils'} = $numfoils;
4402: }
4403: for (my $k=0; $k<$numfoils; $k++) {
4404: my $answer_id = $$settings{$id}{answers}[$k];
4405: my $answer_text = $$settings{$id}{$answer_id}{text};
4406: my $texttype = $$settings{$id}{$answer_id}{texttype};
4407: &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
1.33 raeburn 4408: $answer_text .= &add_images_links('response',$context,$settings,$id,$dirname,$res);
1.30 raeburn 4409: my $iter = $k+1;
4410: if ($context eq 'CSTR') {
4411: $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$answer_id}{order}."\"><startouttext />".$answer_text."<endouttext /></foil>\n";
4412: } else {
4413: $resourcedata{$symb.'text'.$iter} = $answer_text;
4414: $resourcedata{$symb.'value'.$iter} = $$settings{$id}{$answer_id}{order};
4415: if (!grep/^$$settings{$id}{$answer_id}{order}$/,@allorder) {
4416: push(@allorder,$$settings{$id}{$answer_id}{order});
4417: }
4418: }
4419: }
4420: if ($context eq 'CSTR') {
4421: chomp($output);
4422: $output .= qq|
4423: </foilgroup>
4424: </rankresponse>
4425: |;
4426: } else {
4427: @allorder = sort {$a <=> $b} @allorder;
4428: $resourcedata{$symb.'options'} = "('".join("','",@allorder)."')";
4429: }
4430: } elsif ($$settings{$id}{class} eq 'Fill in the Blank') {
4431: my $numerical = 1;
4432: if ($context eq 'DOCS') {
4433: $numerical = 0;
4434: } else {
4435: for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) {
4436: if ($$settings{$id}{correctanswer}[$k] =~ m/([^\d\.]|\.\.)/) {
4437: $numerical = 0;
4438: }
4439: }
4440: }
4441: if ($numerical) {
4442: my $numans;
4443: my $tol;
4444: if (@{$$settings{$id}{correctanswer}} == 1) {
4445: $tol = 5;
4446: $numans = $$settings{$id}{correctanswer}[0];
4447: } else {
4448: my $min = $$settings{$id}{correctanswer}[0];;
4449: my $max = $min;
4450: for (my $k=1; $k<@{$$settings{$id}{correctanswer}}; $k++) {
4451: if ($$settings{$id}{correctanswer}[$k] <= $min) {
4452: $min = $$settings{$id}{correctanswer}[$k];
4453: }
4454: if ($$settings{$id}{correctanswer}[$k] >= $max) {
4455: $max = $$settings{$id}{correctanswer}[$k];
4456: }
4457: }
4458: $numans = ($max + $min)/2;
4459: $tol = 100*($max - $min)/($numans*2);
4460: $tol = 5;
4461: }
4462: if ($context eq 'CSTR') {
4463: $output .= qq|
4464: <numericalresponse answer="$numans">
4465: <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
4466: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures"
4467: />
4468: <textline />
4469: </numericalresponse>
4470: <hintgroup showoncorrect="no">
4471: <numericalhint>
4472: </numericalhint>
4473: <hintpart on="default">
4474: <startouttext/><endouttext />
4475: </hintpart>
4476: </hintgroup>
4477: |;
4478: }
4479: } else {
4480: if ($context eq 'DOCS') {
4481: $resourcedata{$symb.'hiddenparts'} = '!string';
4482: $resourcedata{$symb.'questiontype'} = 'string';
4483: $resourcedata{$symb.'maxfoils'} = 1;
4484: $resourcedata{$symb.'hiddenparts'} = '!string';
4485: $resourcedata{$symb.'stringtype'} = 'ci';
4486: $resourcedata{$symb.'stringanswer'} = $$settings{$id}{correctanswer}[0];
4487: } else {
4488: if (@{$$settings{$id}{correctanswer}} == 1) {
4489: $output .= qq|
4490: <stringresponse answer="$$settings{$id}{correctanswer}[0];" type="ci">
4491: <textline>
4492: </textline>
4493: </stringresponse>
4494: <hintgroup showoncorrect="no">
4495: <stringhint type="cs">
4496: </stringhint>
4497: <hintpart on="default">
4498: <startouttext/><endouttext />
4499: </hintpart>
4500: </hintgroup>
4501: |;
4502: } else {
4503: my @answertext = ();
4504: for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) {
4505: my $answer_text = $$settings{$id}{correctanswer}[$k];
4506: $answer_text =~ s/\|/\|/g;
4507: push @answertext, $answer_text;
4508: }
4509: my $regexpans = join('|',@answertext);
4510: $regexpans = '/^('.$regexpans.')\b/';
4511: $output .= qq|
4512: <stringresponse answer="$regexpans" type="re">
4513: <textline>
4514: </textline>
4515: </stringresponse>
4516: <hintgroup showoncorrect="no">
4517: <stringhint type="cs">
4518: </stringhint>
4519: <hintpart on="default">
4520: <startouttext/><endouttext />
4521: </hintpart>
4522: </hintgroup>
4523: |;
4524: }
4525: }
4526: }
4527: } elsif ($$settings{$id}{class} eq "Matching") {
4528: my @allmatchers = ();
4529: my %matchtext = ();
4530: if ($context eq 'CSTR') {
4531: $output .= qq|
4532: <matchresponse max="10" randomize="yes">
4533: <foilgroup>
4534: <itemgroup>
4535: |;
4536: } else {
4537: $resourcedata{$symb.'newopt'} = '';
4538: $resourcedata{$symb.'delopt'} = '';
4539: $resourcedata{$symb.'hiddenparts'} = '!option';
4540: $resourcedata{$symb.'questiontype'} = 'option';
4541: $resourcedata{$symb.'maxfoils'} = $numfoils;
4542: }
4543: for (my $k=0; $k<$$settings{$id}{allchoices}; $k++) {
4544: my $choice_id = 'rightmatch'.$k;
4545: my $choice_text = $$settings{$id}{$choice_id}{text};
4546: my $texttype = $$settings{$id}{$choice_id}{texttype};
4547: my $choice_plaintext = &remove_html($choice_text);
4548: &process_html(\$choice_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
1.33 raeburn 4549: $choice_text .= &add_images_links($choice_id,$context,$settings,$id,$dirname,$res);
1.30 raeburn 4550: push(@allmatchers,$choice_plaintext);
4551: if ($context eq 'CSTR') {
4552: $output .= qq|
4553: <item name="$choice_id">
4554: <startouttext />$choice_text<endouttext />
4555: </item>
4556: |;
4557: }
4558: }
4559: if ($context eq 'CSTR') {
4560: $output .= qq|
4561: </itemgroup>
4562: |;
4563: }
4564: for (my $k=0; $k<$numfoils; $k++) {
4565: my $answer_id = $$settings{$id}{answers}[$k];
4566: my $answer_text = $$settings{$id}{$answer_id}{text};
4567: my $texttype = $$settings{$id}{$answer_id}{texttype};
4568: &process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir);
1.33 raeburn 4569: $answer_text .= &add_images_links($answer_id,$context,$settings,$id,$dirname,$res);
1.30 raeburn 4570: if ($context eq 'CSTR') {
4571: $output .= '
4572: <foil location="random" value="rightmatch'.$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}.'" name="'.$answer_id.'">
4573: <startouttext />'.$answer_text.'<endouttext />
4574: </foil>
4575: ';
4576: } else {
4577: my $iter = $k+1;
4578: $resourcedata{$symb.'value'.$iter} = "$allmatchers[$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}]";
4579: $resourcedata{$symb.'text'.$iter} = $answer_text;
4580: }
4581: }
4582: if ($context eq 'CSTR') {
4583: $output .= qq|
4584: </foilgroup>
4585: </matchresponse>
4586: |;
4587: } else {
4588: $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')";
4589: }
4590: }
4591: }
4592: if ($context eq 'CSTR') {
4593:
4594: $output .= qq|
4595: <postanswerdate>
4596: $$settings{$id}{solutionfeedback}{text}
4597: </postanswerdate>
4598: </problem>
4599: |;
4600: my $title = $$settings{title};
4601: $title =~ s/\s/_/g;
4602: $title =~ s/\W//g;
4603: $title .= '_'.$id;
4604: open(PROB,">:utf8", "$newdir/$title.problem");
4605: print PROB $output;
4606: close PROB;
4607: } else {
4608: # put %resourcedata;
4609: my $reply=&Apache::lonnet::cput
4610: ('resourcedata',\%resourcedata,$cdom,$cnum);
4611: }
4612: }
1.20 raeburn 4613: }
4614:
4615: sub retrieve_image {
4616: my ($context,$res,$dirname,$cdom,$cname,$docroot,$destdir,$urlpath,$filename) = @_;
4617: my $contents;
4618: my $url = $urlpath.$filename;
4619: my $ua=new LWP::UserAgent;
4620: my $request=new HTTP::Request('GET',$url);
4621: my $response=$ua->request($request);
4622: if ($response->is_success) {
4623: $contents = $response->content;
4624: if (!-e "$docroot/$res") {
4625: mkdir("$docroot/$res",0755);
4626: }
4627: if (!-e "$docroot/$res/webimages") {
4628: mkdir("$docroot/$res/webimages",0755);
4629: }
4630: open(my $fh,">$docroot/$res/webimages/$filename");
4631: print $fh $contents;
4632: close($fh);
4633: if ($context eq 'DOCS') {
4634: my $copyfile = $dirname.'/'.$filename;
4635: my $source = "$docroot/$res/webimages/$filename";
4636: my $fileresult;
4637: if (-e $source) {
1.31 raeburn 4638: $fileresult = &Apache::lonnet::process_coursefile('copy',$cname,$cdom,$copyfile,$source);
1.20 raeburn 4639: }
4640: return $fileresult;
4641: } elsif ($context eq 'CSTR') {
4642: if (!-e "$destdir/resfiles/$res") {
4643: mkdir("$destdir/resfiles/$res",0755);
4644: }
4645: if (!-e "$destdir/resfiles/$res/webimages") {
4646: mkdir("$destdir/resfiles/$res/webimages",0755);
4647: }
4648: rename("$docroot/$res/webimages/$filename","$destdir/resfiles/$res/webimages/$filename");
4649: return 'ok';
4650: }
4651: } else {
4652: return -1;
4653: }
1.15 raeburn 4654: }
4655:
1.2 raeburn 4656: # ---------------------------------------------------------------- Process Blackboard Announcements
4657: sub process_announce {
1.3 raeburn 4658: my ($res,$docroot,$destdir,$settings,$globalresref,$seqstem,$resrcfiles) = @_;
1.2 raeburn 4659: my $xmlfile = $docroot.'/'.$res.".dat";
4660: my @state = ();
4661: my @assess = ();
4662: my $id;
4663: my $p = HTML::Parser->new
4664: (
4665: xml_mode => 1,
4666: start_h =>
4667: [sub {
4668: my ($tagname, $attr) = @_;
4669: push @state, $tagname;
4670: if ("@state" eq "ANNOUNCEMENT TITLE") {
4671: $$settings{title} = $attr->{value};
4672: $$settings{startassessment} = ();
1.7 raeburn 4673: } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISHTML") {
1.2 raeburn 4674: $$settings{ishtml} = $attr->{value};
4675: } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISNEWLINELITERAL" ) {
4676: $$settings{isnewline} = $attr->{value};
4677: } elsif ("@state" eq "ANNOUNCEMENT ISPERMANENT" ) {
4678: $$settings{ispermanent} = $attr->{value};
4679: } elsif ("@state" eq "ANNOUNCEMENT DATES UPDATED") {
4680: $$settings{dates} = $attr->{value};
4681: } elsif ("@state" eq "ANNOUNCEMENT FILES STARTASSESSMENT" ) {
4682: $id = $attr->{id};
4683: %{$$settings{startassessment}{$id}} = ();
4684: push @assess,$id;
4685: } elsif ("@state" eq "ANNOUNCEMENT FILES STARTASSESSMENT ATTRIB" ) {
4686: my $key = $attr->{key};
4687: $$settings{startassessment}{$id}{$key} = $attr->{value};
4688: }
4689: }, "tagname, attr"],
4690: text_h =>
4691: [sub {
4692: my ($text) = @_;
4693: if ("@state" eq "ANNOUNCEMENT DESCRIPTION TEXT") {
4694: $$settings{text} = $text;
4695: }
4696: }, "dtext"],
4697: end_h =>
4698: [sub {
4699: my ($tagname) = @_;
4700: pop @state;
4701: }, "tagname"],
4702: );
4703: $p->unbroken_text(1);
4704: $p->parse_file($xmlfile);
4705: $p->eof;
4706:
4707: if (defined($$settings{text})) {
4708: if ($$settings{ishtml} eq "false") {
4709: if ($$settings{isnewline} eq "true") {
4710: $$settings{text} =~ s#\n#<br/>#g;
4711: }
4712: } else {
4713: $$settings{text} = &HTML::Entities::decode($$settings{text});
4714: }
4715: }
4716:
4717: if (@assess > 0) {
4718: foreach my $id (@assess) {
1.3 raeburn 4719: $$settings{text} = "A $$settings{startassessment}{$id}{assessment_type}, entitled $$globalresref{$$settings{startassessment}{$id}{assessment_id}}{title} is available. Click <a href='$seqstem/pages/$$settings{startassessment}{$id}{assessment_id}.page' target='quizpage'>here</a> to enter the page that contains the problems in this assessment.";
1.2 raeburn 4720: }
4721: }
4722:
4723: open(FILE,">$destdir/resfiles/$res.html");
4724: push @{$resrcfiles}, "$res.html";
4725: print FILE qq|<html>
4726: <head>
4727: <title>$$settings{title}</title>
4728: </head>
4729: <body bgcolor='#ffffff'>
4730: <table>
4731: <tr>
1.3 raeburn 4732: <td bgcolor='#CCCCFF'>$$settings{title} - announcement date: $$settings{dates}</td>
1.2 raeburn 4733: </tr>
4734: </table>
4735: <br/>
4736: $$settings{text}
4737: |;
4738: print FILE qq|
4739: </body>
4740: </html>|;
4741: close(FILE);
4742: }
4743:
4744: # ---------------------------------------------------------------- Process Blackboard Content
4745: sub process_content {
1.10 raeburn 4746: my ($cms,$res,$context,$docroot,$destdir,$settings,$dom,$user,$resrcfiles,$packages,$hrefs) = @_;
1.2 raeburn 4747: my $xmlfile = $docroot.'/'.$res.".dat";
4748: my $destresdir = $destdir;
1.7 raeburn 4749: if ($context eq 'CSTR') {
1.15 raeburn 4750: $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
1.7 raeburn 4751: } elsif ($context eq 'DOCS') {
4752: $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
4753: }
1.10 raeburn 4754: my $filetag = '';
4755: if ($cms eq 'bb5') {
4756: $filetag = 'FILEREF';
4757: } elsif ($cms eq 'bb6') {
4758: $filetag = 'FILE';
4759: }
1.2 raeburn 4760: my $filecount = 0;
4761: my @allrelfiles = ();
4762: my @state;
4763: @{$$settings{files}} = ();
4764: my $p = HTML::Parser->new
4765: (
4766: xml_mode => 1,
4767: start_h =>
4768: [sub {
4769: my ($tagname, $attr) = @_;
4770: push @state, $tagname;
1.10 raeburn 4771: if ("@state" eq "CONTENT ") {
1.2 raeburn 4772: %{$$settings{maindata}} = ();
1.10 raeburn 4773: } elsif ("@state" eq "CONTENT TITLECOLOR") {
4774: $$settings{titlecolor} = $attr->{value};
1.7 raeburn 4775: } elsif ("@state" eq "CONTENT MAINDATA TEXTCOLOR") {
1.2 raeburn 4776: $$settings{maindata}{color} = $attr->{value};
1.7 raeburn 4777: } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISHTML") {
1.2 raeburn 4778: $$settings{maindata}{ishtml} = $attr->{value};
1.7 raeburn 4779: } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISNEWLINELITERAL") {
1.2 raeburn 4780: $$settings{maindata}{isnewline} = $attr->{value};
1.10 raeburn 4781: } elsif ("@state" eq "CONTENT BODY TYPE") {
4782: $$settings{maindata}{bodytype} = $attr->{value};
1.2 raeburn 4783: } elsif ("@state" eq "CONTENT FLAGS ISAVAILABLE" ) {
4784: $$settings{isavailable} = $attr->{value};
4785: } elsif ("@state" eq "CONTENT FLAGS ISFOLDER" ) {
4786: $$settings{isfolder} = $attr->{value};
4787: } elsif ("@state" eq "CONTENT FLAGS LAUNCHINNEWWINDOW" ) {
4788: $$settings{newwindow} = $attr->{value};
1.10 raeburn 4789: } elsif ("@state" eq "CONTENT FILES $filetag") {
1.2 raeburn 4790: %{$$settings{files}[$filecount]} = ();
4791: %{$$settings{files}[$filecount]{registry}} = ();
4792: } elsif ("@state" eq "CONTENT FILES FILEREF RELFILE" ) {
4793: $$settings{files}[$filecount]{'relfile'} = $attr->{value};
4794: push @allrelfiles, $attr->{value};
1.10 raeburn 4795: } elsif ("@state" eq "CONTENT FILES $filetag MIMETYPE") {
1.2 raeburn 4796: $$settings{files}[$filecount]{mimetype} = $attr->{value};
1.10 raeburn 4797: } elsif ("@state" eq "CONTENT FILES $filetag CONTENTTYPE") {
1.2 raeburn 4798: $$settings{files}[$filecount]{contenttype} = $attr->{value};
1.10 raeburn 4799: } elsif ("@state" eq "CONTENT FILES $filetag FILEACTION") {
1.2 raeburn 4800: $$settings{files}[$filecount]{fileaction} = $attr->{value};
1.10 raeburn 4801: } elsif ("@state" eq "CONTENT FILES $filetag PACKAGEPARENT") {
1.2 raeburn 4802: $$settings{files}[$filecount]{packageparent} = $attr->{value};
1.10 raeburn 4803: } elsif ("@state" eq "CONTENT FILES $filetag LINKNAME") {
1.2 raeburn 4804: $$settings{files}[$filecount]{linkname} = $attr->{value};
1.10 raeburn 4805: } elsif ("@state" eq "CONTENT FILES $filetag REGISTRY REGISTRYENTRY") {
1.2 raeburn 4806: my $key = $attr->{key};
4807: $$settings{files}[$filecount]{registry}{$key} = $attr->{value};
4808: }
4809: }, "tagname, attr"],
4810: text_h =>
4811: [sub {
4812: my ($text) = @_;
4813: if ("@state" eq "CONTENT TITLE") {
4814: $$settings{title} = $text;
1.10 raeburn 4815: } elsif ( ("@state" eq "CONTENT MAINDATA TEXT") || ("@state" eq "CONTENT BODY TEXT") ) {
1.2 raeburn 4816: $$settings{maindata}{text} = $text;
1.10 raeburn 4817: } elsif ("@state" eq "CONTENT FILES $filetag REFTEXT") {
1.2 raeburn 4818: $$settings{files}[$filecount]{reftext} = $text;
1.10 raeburn 4819: } elsif ("@state" eq "CONTENT FILES FILE NAME" ) {
4820: $$settings{files}[$filecount]{'relfile'} = $text;
4821: push @allrelfiles, $text;
1.2 raeburn 4822: }
4823: }, "dtext"],
4824: end_h =>
4825: [sub {
4826: my ($tagname) = @_;
1.10 raeburn 4827: if ("@state" eq "CONTENT FILES $filetag") {
1.2 raeburn 4828: $filecount ++;
4829: }
4830: pop @state;
4831: }, "tagname"],
4832: );
4833: $p->unbroken_text(1);
4834: $p->parse_file($xmlfile);
4835: $p->eof;
4836: my $linktag = '';
4837: my $fontcol = '';
4838: if (@{$$settings{files}} > 0) {
4839: for (my $filecount=0; $filecount<@{$$settings{files}}; $filecount++) {
4840: if ($$settings{files}[$filecount]{'fileaction'} eq 'embed') {
4841: if ( $$settings{files}[$filecount]{reftext} =~ m#<\!\-\-\s_(\d+)\\_\s\-\-\>#) {
4842: my $newtag = qq|<img src="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"/>|;
4843: $$settings{maindata}{text} =~ s#<\!\-\-\s_/($1)\\_\s\-\-\>#$newtag#;
4844: } elsif ( $$settings{files}[$filecount]{reftext} =~m#^_/(\d+)\\_$# ) {
4845: my $reftag = $1;
4846: my $newtag;
4847: if ($$settings{files}[$filecount]{mimetype} =~ m/^image/) {
4848: $newtag = qq|<img src="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"|;
4849: if ( defined($$settings{files}[$filecount]{registry}{alttext}) ) {
4850: $newtag .= qq| alt="$$settings{files}[$filecount]{registry}{alttext}"|;
4851: }
4852: if ( defined($$settings{files}[$filecount]{registry}{alignment}) )
4853: {
4854: $newtag .= qq| align="$$settings{files}[$filecount]{registry}{alignment}"|;
1.1 raeburn 4855: }
1.2 raeburn 4856: if ( defined($$settings{files}[$filecount]{registry}{border}) ) {
4857: $newtag .= qq| border="$$settings{files}[$filecount]{registry}{border}"|;
4858: }
4859: $newtag .= " />";
4860: my $reftext = $$settings{files}[$filecount]{reftext};
4861: my $fname = $$settings{files}[$filecount]{'relfile'};
4862: $$settings{maindata}{text} =~ s/<!\-\-\sCOMMENT\sBLOCK\sFOR\sEMBEDDED\sFILE:\s$fname[\s\n]+DO\sNOT\sEDIT\sTHIS\sCOMMENT\sBLOCK[\s\n]+//;
4863: # $$settings{maindata}{text} =~ s/DO\sNOT\sEDIT\sTHIS\sCOMMENT\sBLOCK[\s\n]+//;
4864: $$settings{maindata}{text} =~ s/Move\swhole\scomment\sto\schange\sfile\splacement\swithin\spage\.[\s\n]+//;
4865: $$settings{maindata}{text} =~ s/_\/$reftag\\_/$newtag/;
4866: $$settings{maindata}{text} =~ s/END\sOF\sBLOCK\sON\sNEXT\sLINE[\s\n]+//;
4867: $$settings{maindata}{text} =~ s/\-\->//;
4868: # $$settings{maindata}{text} =~ s/<!\-\-\sCOMMENT\sBLOCK\sFOR\sEMBEDDED\sFILE:\s$fname[\s\n]+DO\sNOT\sEDIT\sTHIS\sCOMMENT\sBLOCK[\s\n\]+_\/$reftag\\_[\s\n]+END\sOF\sBLOCK\sON\sNEXT\sLINE[\s\n\]+\-\->/$newtag/;
4869: # print STDERR $$settings{maindata}{text};
4870: }
4871: } else {
4872: my $filename=$$settings{files}[$filecount]{'relfile'};
4873: my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}";
1.10 raeburn 4874: $$settings{maindata}{text} =~ s#(src|SRC|value)=("|")$filename("|")#$1="$newfilename"#g;
1.2 raeburn 4875: }
4876: } elsif ($$settings{files}[$filecount]{fileaction} eq 'link') {
4877: unless (($$settings{files}[$filecount]{packageparent} ne '') && (grep/^$$settings{files}[$filecount]{packageparent}$/,@{$$settings{files}}) ) {
4878: $linktag .= qq|<a href="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"|;
4879: if ($$settings{newwindow} eq "true") {
4880: $linktag .= qq| target="$res$filecount"|;
1.1 raeburn 4881: }
1.2 raeburn 4882: foreach my $entry (keys %{$$settings{files}[$filecount]{registry}}) {
4883: $linktag .= qq| $entry="$$settings{files}[$filecount]{registry}{$entry}"|;
1.1 raeburn 4884: }
1.2 raeburn 4885: $linktag .= qq|>$$settings{files}[$filecount]{linkname}</a><br/>\n|;
1.1 raeburn 4886: }
1.10 raeburn 4887: } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'PACKAGE') || ($$settings{files}[$filecount]{fileaction} eq 'package') ) {
4888: my $open_package = '';
4889: if ($$settings{files}[$filecount]{'relfile'} =~ m|\.zip$|i) {
4890: $open_package = &expand_zip("$docroot/$res",$$settings{files}[$filecount]{'relfile'});
4891: }
4892: if ($open_package eq 'ok') {
4893: opendir(DIR,"$docroot/$res");
4894: my @dircontents = grep(!/^\./,readdir(DIR));
4895: closedir(DIR);
4896: push @{$resrcfiles}, @dircontents;
4897: @{$$hrefs{$res}} = @dircontents;
4898: push @{$packages}, $res;
4899: }
4900: } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'BROKEN_IMAGE') && ($cms eq 'bb6') ) {
4901: my $filename=$$settings{files}[$filecount]{'relfile'};
4902: my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}";
4903: $$settings{maindata}{text} =~ s#(src|SRC|value)=("|")$filename("|")#$1="$newfilename"#g;
4904: } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'LINK') && ($cms eq 'bb6') ) {
4905: my $filename=$$settings{files}[$filecount]{'relfile'};
4906: my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}";
4907: my $filetitle = $$settings{files}[$filecount]{'linkname'};
4908: $$settings{maindata}{text} = '<a href="'.$newfilename.'">'.$filetitle.'</a><br /><br />'. $$settings{maindata}{text};
1.1 raeburn 4909: }
1.2 raeburn 4910: }
4911: }
4912: if (defined($$settings{maindata}{textcolor})) {
4913: $fontcol = qq|<font color="$$settings{maindata}{textcolor}">|;
4914: }
4915: if (defined($$settings{maindata}{text})) {
1.10 raeburn 4916: if ($$settings{maindata}{bodytype} eq "S") {
4917: $$settings{maindata}{text} =~ s#\n#<br/>#g;
4918: }
1.2 raeburn 4919: if ($$settings{maindata}{ishtml} eq "false") {
4920: if ($$settings{maindata}{isnewline} eq "true") {
4921: $$settings{maindata}{text} =~ s#\n#<br/>#g;
4922: }
4923: } else {
1.10 raeburn 4924: # $$settings{maindata}{text} = &HTML::Entities::decode($$settings{maindata}{text});
1.2 raeburn 4925: }
4926: }
4927:
1.14 raeburn 4928: if (!open(FILE,">$destdir/resfiles/$res.html")) {
4929: &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
4930: } else {
4931: push @{$resrcfiles}, "$res.html";
4932: my $htmldoc = 0;
4933: # if ($$settings{maindata}{text} =~ m-<(html|HTML)>.+<\\(html|HTML)-) {
4934: if ($$settings{maindata}{text} =~ m-<(html|HTML)>-) {
4935: $htmldoc = 1;
4936: }
4937: unless ($htmldoc) {
4938: print FILE qq|<html>
1.2 raeburn 4939: <head>
4940: <title>$$settings{title}</title>
4941: </head>
4942: <body bgcolor='#ffffff'>
4943: $fontcol
4944: |;
1.14 raeburn 4945: }
4946: unless ($$settings{title} eq '') {
4947: print FILE qq|$$settings{title}<br/><br/>\n|;
4948: }
4949: print FILE qq|
1.2 raeburn 4950: $$settings{maindata}{text}
4951: $linktag|;
1.14 raeburn 4952: unless ($htmldoc) {
4953: if (defined($$settings{maindata}{textcolor})) {
4954: print FILE qq|</font>|;
4955: }
4956: print FILE qq|
1.2 raeburn 4957: </body>
4958: </html>|;
1.14 raeburn 4959: }
4960: close(FILE);
1.10 raeburn 4961: }
1.2 raeburn 4962: }
4963:
4964:
4965: sub process_angelboards {
4966: my ($context,$destdir,$boards,$timestamp,$crs,$cdom,$uname,$db_handling,$messages,$items,$resources,$hrefs,$tempdir,$longcrs) = @_;
4967: for (my $i=0; $i<@{$boards}; $i++) {
4968: my %msgidx = ();
4969: my $forumtext = '';
4970: my $boardname = 'bulletinpage_'.$$timestamp[$i];
4971: my $forumfile = $tempdir.'/_assoc/'.$$boards[$i].'/pg'.$$boards[$i].'.htm';
4972: my @state = ();
4973: my $p = HTML::Parser->new
4974: (
4975: xml_mode => 1,
4976: start_h =>
4977: [sub {
4978: my ($tagname, $attr) = @_;
4979: push @state, $tagname;
4980: }, "tagname, attr"],
4981: text_h =>
4982: [sub {
4983: my ($text) = @_;
4984: if ("@state" eq "html body div div") {
4985: $forumtext = $text;
4986: }
4987: }, "dtext"],
4988: end_h =>
4989: [sub {
4990: my ($tagname) = @_;
4991: pop @state;
4992: }, "tagname"],
4993: );
4994: $p->parse_file($forumfile);
4995: $p->eof;
4996:
4997: my %boardinfo = (
4998: 'aaa_title' => $$items{$$resources{$$boards[$i]}{revitm}}{title},
4999: 'bbb_content' => $forumtext,
5000: 'ccc_webreferences' => '',
5001: 'uploaded.lastmodified' => time,
5002: );
5003: my $msgcount = 0;
5004:
5005: my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$cdom,$crs);
5006: if ($db_handling eq 'importall') {
5007: foreach my $msg_id (@{$$messages{$$boards[$i]}}) {
5008: $msgcount ++;
5009: $msgidx{$msg_id} = $msgcount;
5010: my %contrib = (
5011: 'sendername' => 'NoName',
5012: 'senderdomain' => $cdom,
5013: 'screenname' => '',
5014: 'message' => $$items{$$resources{$msg_id}{revitm}}{title}
5015: );
5016: unless ( $$items{$$resources{$msg_id}{revitm}}{parentseq} eq $$resources{$$boards[$i]}{revitm} ) {
5017: unless ( $msgidx{$$items{$$items{$$resources{$msg_id}{revitm}}{parentseq}}{resnum}} eq ''){
5018: $contrib{replyto} = $msgidx{$$items{$$items{$$resources{$msg_id}{revitm}}{parentseq}}{resnum}};
1.1 raeburn 5019: }
1.2 raeburn 5020: }
5021: if ( @{$$hrefs{$msg_id}} > 1 ) {
5022: my $newurl = '';
5023: foreach my $file (@{$$hrefs{$msg_id}}) {
5024: unless ($file eq 'pg'.$msg_id.'.htm') {
5025: $newurl = $msg_id.$file;
5026: unless ($longcrs eq '') {
5027: if ($context eq 'CSTR') {
5028: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles") {
5029: mkdir("/home/httpd/lonUsers/$cdom/$longcrs/userfiles",0755);
5030: }
5031: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl") {
5032: rename("$destdir/resfiles/$msg_id/$file","/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl");
5033: }
5034: }
5035: $contrib{attachmenturl} = '/uploaded/'.$cdom.'/'.$crs.'/'.$file;
5036: }
1.1 raeburn 5037: }
5038: }
5039: }
1.2 raeburn 5040: my $xmlfile = $tempdir.'/_assoc/'.$msg_id.'/'.$$resources{$msg_id}{file};
5041: &angel_message($msg_id,\%contrib,$xmlfile);
5042: unless ($$resources{$msg_id}{file} eq '') {
5043: unlink($xmlfile);
5044: }
5045: my $symb = 'bulletin___'.$$timestamp[$i].'___adm/wrapper/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$i].'/bulletinboard';
5046: my $postresult = &addposting($symb,\%contrib,$cdom,$crs);
5047: }
5048: }
5049: }
5050: }
5051:
5052: # ---------------------------------------------------------------- Process ANGEL message board messages
5053: sub angel_message {
5054: my ($msg_id,$contrib,$xmlfile) = @_;
5055: my @state = ();
5056: my $p = HTML::Parser->new
5057: (
5058: xml_mode => 1,
5059: start_h =>
5060: [sub {
5061: my ($tagname, $attr) = @_;
5062: push @state, $tagname;
5063: }, "tagname, attr"],
5064: text_h =>
5065: [sub {
5066: my ($text) = @_;
5067: if ("@state" eq "html body table tr td div small span") {
5068: $$contrib{'plainname'} = $text;
5069: } elsif ("@state" eq "html body div div") {
5070: $$contrib{'message'} .= '<br /><br />'.$text;
5071: }
5072: }, "dtext"],
5073: end_h =>
5074: [sub {
5075: my ($tagname) = @_;
5076: pop @state;
5077: }, "tagname"],
5078: );
5079: $p->parse_file($xmlfile);
5080: $p->eof;
5081: }
5082:
5083: # ---------------------------------------------------------------- ANGEL content
5084: sub angel_content {
5085: my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
5086: my $xmlfile = $docroot.'/_assoc/'.$res.'/pg'.$res.'.htm';
5087: my $filecount = 0;
5088: my $firstline;
5089: my $lastline;
5090: my @buffer = ();
5091: my @state;
5092: @{$$settings{links}} = ();
5093: my $p = HTML::Parser->new
5094: (
5095: xml_mode => 1,
5096: start_h =>
5097: [sub {
5098: my ($tagname, $attr) = @_;
5099: push @state, $tagname;
5100: }, "tagname, attr"],
5101: text_h =>
5102: [sub {
5103: my ($text) = @_;
5104: if ("@state" eq "html body table tr td div small span") {
5105: $$settings{'subtitle'} = $text;
5106: } elsif ("@state" eq "html body div div") {
5107: $$settings{'text'} = $text;
5108: } elsif ("@state" eq "html body div div a") {
5109: push @{$$settings{'links'}}, $text;
5110: }
5111: }, "dtext"],
5112: end_h =>
5113: [sub {
5114: my ($tagname) = @_;
5115: pop @state;
5116: }, "tagname"],
5117: );
5118: $p->parse_file($xmlfile);
5119: $p->eof;
5120: if ($type eq "PAGE") {
5121: open(FILE,"<$xmlfile");
5122: @buffer = <FILE>;
5123: close(FILE);
5124: chomp(@buffer);
5125: $firstline = -1;
5126: $lastline = 0;
5127: for (my $i=0; $i<@buffer; $i++) {
5128: if (($firstline == -1) && ($buffer[$i] =~ m/<div\sclass="normalDiv"><div\sclass="normalSpan">/)) {
5129: $firstline = $i;
5130: $buffer[$i] = substr($buffer[$i],index($buffer[$i],'"normalSpan"')+13);
5131: }
5132: if (($firstline > -1) && ($buffer[$i] =~ m-<p></p></div></div>-)) {
5133: $buffer[$i] = substr($buffer[$i],0,index($buffer[$i],'<p></p></div></div>'));
5134: $lastline = $i;
1.1 raeburn 5135: }
5136: }
5137: }
1.2 raeburn 5138: open(FILE,">$destdir/resfiles/$res.html");
5139: push @{$resrcfiles}, "$res.html";
5140: print FILE qq|<html>
5141: <head>
5142: <title>$title</title>
5143: </head>
5144: <body bgcolor='#ffffff'>
5145: |;
5146: unless ($title eq '') {
5147: print FILE qq|<b>$title</b><br/>\n|;
5148: }
5149: unless ($$settings{subtitle} eq '') {
5150: print FILE qq|$$settings{subtitle}<br/>\n|;
5151: }
5152: print FILE "<br/>\n";
5153: if ($type eq "LINK") {
5154: foreach my $link (@{$$settings{links}}) {
5155: print FILE qq|<a href="$link">$link</a><br/>\n|;
5156: }
5157: } elsif ($type eq "PAGE") {
5158: if ($firstline > -1) {
5159: for (my $i=$firstline; $i<=$lastline; $i++) {
5160: print FILE "$buffer[$i]\n";
5161: }
5162: }
5163: }
5164: print FILE qq|
5165: </body>
5166: </html>|;
5167: close(FILE);
1.1 raeburn 5168: }
5169:
1.15 raeburn 5170: # ---------------------------------------------------------------- WebCT content
5171: sub webct4_content {
5172: my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
5173: if (!open(FILE,">$destdir/resfiles/$res.html")) {
5174: &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
5175: } else {
5176: push(@{$resrcfiles}, "$res.html");
5177: my $linktag = '';
5178: if (defined($$settings{url})) {
5179: $linktag = qq|<a href="$$settings{url}"|;
5180: if ($title ne '') {
5181: $linktag .= qq|>$title</a>|;
5182: } else {
5183: $linktag .= qq|>$$settings{url}|;
5184: }
5185: }
5186: print FILE qq|<html>
5187: <head>
5188: <title>$title</title>
5189: </head>
5190: <body bgcolor='#ffffff'>
5191: $linktag
5192: </body>
5193: </html>|;
5194: close(FILE);
5195: }
5196: }
5197:
1.30 raeburn 5198: sub process_html {
5199: my ($text,$caller,$html_cond,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir) = @_;
1.33 raeburn 5200: my $pathstart;
5201: if ($context eq 'CSTR') {
5202: $pathstart = '../..';
5203: } else {
5204: $pathstart = $dirname;
5205: }
1.30 raeburn 5206: if ($caller eq 'bb5') {
5207: if ($html_cond eq 'true') {
5208: $$text = &HTML::Entities::decode($$text);
5209: }
5210: } elsif ($caller eq 'bb6') {
5211: if ($html_cond eq 'HTML') {
5212: $$text = &HTML::Entities::decode($$text);
5213: }
5214: }
5215: if ($$text =~ m#<img src=['"]?(https?://[^\s]+/)([^/\s\'"]+)['"]?[^>]*>#) {
5216: if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') {
1.33 raeburn 5217: $$text =~ s#(<img src=['"]?)(https?://[^\s]+/)([^/\s'"]+)(['"]?[^>]*>)#$1$pathstart/resfiles/$res/webimages/$3$4#g;
1.30 raeburn 5218: }
5219: }
5220: $$text =~ s#(<img src=[^>]+)/*>#$1 />#gi;
5221: $$text =~ s#<br>#<br />#g;
5222: return;
5223: }
5224:
5225: sub add_images_links {
1.33 raeburn 5226: my ($type,$context,$settings,$id,$dirname,$res) = @_;
5227: my ($image,$imglink,$url,$pathstart);
5228: if ($context eq 'CSTR') {
5229: $pathstart = '../..';
5230: } else {
5231: $pathstart = $dirname;
5232: }
1.30 raeburn 5233: if ((defined($$settings{$id}{$type}{image})) && ($$settings{$id}{$type}{image} ne '')) {
5234: if ( $$settings{$id}{$type}{style} eq 'Inline' ) {
1.33 raeburn 5235: $image = qq|<br /><img src="$pathstart/resfiles/$res/$$settings{$id}{$type}{image}" alt="$$settings{$id}{$type}{label}"/><br />|;
1.30 raeburn 5236: } else {
1.33 raeburn 5237: $imglink = qq|<br /><a href="$pathstart/resfiles/$res/$$settings{$id}{$type}{image}">$$settings{$id}{$type}{label}</a><br />|;
1.30 raeburn 5238: }
5239: }
5240: if ((defined($$settings{$id}{$type}{link})) && ($$settings{$id}{$type}{link} ne '' )) {
5241: $url = qq|<br /><a href="$$settings{$id}{$type}{link}">$$settings{$id}{$type}{linkname}</a><br />|;
5242: }
5243: return $image.$imglink.$url;
5244: }
5245:
5246: sub remove_html {
5247: my ($choice_text) = @_;
5248: return $choice_text;
5249: }
5250:
5251:
1.1 raeburn 5252: 1;
5253: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>