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