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