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