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