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