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