Annotation of loncom/imspackages/imsprocessor.pm, revision 1.9
1.1 raeburn 1: package Apache::imsprocessor;
2:
3: use Apache::lonnet;
4: use LONCAPA::Configuration;
1.2 raeburn 5: use strict;
1.3 raeburn 6:
7: sub ims_config {
8: my ($areas,$cmsmap,$areaname) = @_;
9: @{$areas} = ("doc","extlink","announce","staff","board","quiz","survey","pool","users");
10: %{$$cmsmap{bb5}} = (
11: announce => 'resource/x-bb-announcement',
12: board => 'resource/x-bb-discussionboard',
13: doc => 'resource/x-bb-document',
14: extlink => 'resource/x-bb-externallink',
15: pool => 'assessment/x-bb-pool',
16: quiz => 'assessment/x-bb-quiz',
17: staff => 'resource/x-bb-staffinfo',
18: survey => 'assessment/x-bb-survey',
19: users => 'course/x-bb-user',
20: );
21:
22: %{$$cmsmap{angel}} = (
23: board => 'BOARD',
24: extlink => 'LINK',
25: msg => 'MESSAGE',
26: quiz => 'QUIZ',
27: survey => 'FORM',
28: );
29:
30: @{$$cmsmap{angel}{doc}} = ('FILE','PAGE');
31:
32:
33: %{$areaname} = (
34: announce => 'Announcements',
35: board => 'Discussion Boards',
36: doc => 'Documents, pages, and folders',
37: extlink => 'Links to external sites',
38: pool => 'Question pools',
39: quiz => 'Quizzes',
40: staff => 'Staff information',
41: survey => 'Surveys',
42: users => 'Enrollment',
43: );
44:
45: }
1.1 raeburn 46:
47: sub create_tempdir {
1.3 raeburn 48: my ($context,$pathinfo,$timenow) = @_;
1.1 raeburn 49: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
50: my $tempdir;
1.3 raeburn 51: if ($context eq 'DOCS') {
1.1 raeburn 52: $tempdir = $$configvars{'lonDaemons'}.'/tmp/'.$pathinfo;
53: if (!-e "$tempdir") {
1.2 raeburn 54: mkdir("$tempdir",0770);
55: }
56: $tempdir .= '/'.$timenow;
57: if (!-e "$tempdir") {
58: mkdir("$tempdir",0770);
59: }
1.3 raeburn 60: } elsif ($context eq "CSTR") {
1.1 raeburn 61: if (!-e "$pathinfo/temp") {
1.2 raeburn 62: mkdir("$pathinfo/temp",0770);
1.1 raeburn 63: }
64: $tempdir = $pathinfo.'/temp';
65: }
66: return $tempdir;
67: }
68:
1.3 raeburn 69: sub uploadzip {
70: my ($context,$tempdir,$source) = @_;
71: my $fname;
72: if ($context eq 'DOCS') {
73: $fname=$ENV{'form.uploadname.filename'};
74: # Replace Windows backslashes by forward slashes
75: $fname=~s/\\/\//g;
76: # Get rid of everything but the actual filename
77: $fname=~s/^.*\/([^\/]+)$/$1/;
78: # Replace spaces by underscores
79: $fname=~s/\s+/\_/g;
80: # Replace all other weird characters by nothing
81: $fname=~s/[^\w\.\-]//g;
82: # See if there is anything left
83: unless ($fname) { return 'error: no uploaded file'; }
84: # Save the file
85: chomp($ENV{'form.uploadname'});
86: open(my $fh,'>'.$tempdir.'/'.$fname);
87: print $fh $ENV{'form.uploadname'};
88: close($fh);
89: } elsif ($context eq 'CSTR') {
90: if ($source =~ m/\/([^\/]+)$/) {
91: $fname = $1;
92: my $destination = $tempdir.'/'.$fname;
93: rename($source,$destination);
94: }
95: }
96: return $fname;
97: }
98:
1.1 raeburn 99: sub expand_zip {
100: my ($tempdir,$filename) = @_;
101: my $zipfile = "$tempdir/$filename";
102: if ($filename =~ m|\.zip$|i) {
1.9 ! raeburn 103: # unzip can cause an sh launch which can pass along all of %ENV
! 104: # which can be too large for /bin/sh to handle
! 105: my %oldENV=%ENV;
! 106: undef(%ENV);
1.1 raeburn 107: open(OUTPUT, "unzip -o $zipfile -d $tempdir 2> /dev/null |");
108: close(OUTPUT);
1.9 ! raeburn 109: %ENV=%oldENV;
! 110: undef(%oldENV);
1.1 raeburn 111: } else {
112: return 'nozip';
113: }
114: if ($filename =~ m|\.zip$|i) {
115: unlink($zipfile);
116: }
117: return 'ok';
118: }
119:
120: sub process_manifest {
1.2 raeburn 121: my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo) = @_;
1.1 raeburn 122: my %toc = (
123: bb5 => 'tableofcontents',
124: angel => 'organization',
125: );
1.2 raeburn 126: my %contents = ();
1.1 raeburn 127: my @state = ();
128: my $itm = '';
129: my $identifier = '';
130: my @seq = "Top";
131: my $lastitem;
1.2 raeburn 132: %{$$items{'Top'}} = (
133: contentscount => 0,
134: resnum => 'toplevel',
135: );
1.3 raeburn 136: %{$$resources{'toplevel'}} = (
137: revitm => 'Top'
138: );
1.2 raeburn 139:
140: if ($cms eq 'angel') {
141: $$resources{'toplevel'}{type} = "FOLDER";
142: } elsif ($cms eq 'bb5') {
143: $$resources{'toplevel'}{type} = 'resource/x-bb-document';
144: }
145:
1.1 raeburn 146:
147: unless (-e "$tempdir/imsmanifest.xml") {
148: return 'nomanifest';
149: }
150:
151: my $xmlfile = $tempdir.'/imsmanifest.xml';
152: my $p = HTML::Parser->new
153: (
154: xml_mode => 1,
155: start_h =>
156: [sub {
157: my ($tagname, $attr) = @_;
158: push @state, $tagname;
159: my $num = @state - 3;
160: my $start = $num;
161: my $statestr = '';
162: foreach (@state) {
163: $statestr .= "$_ ";
164: }
165: if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $toc{$cms}) ) {
166: my $searchstr = "manifest organizations $toc{$cms}";
167: while ($num > 0) {
168: $searchstr .= " item";
169: $num --;
170: }
171: if (("@state" eq $searchstr) && (@state > 3)) {
172: $itm = $attr->{identifier};
173: %{$$items{$itm}} = ();
174: $$items{$itm}{contentscount} = 0;
175: if ($cms eq 'bb5') {
176: $$items{$itm}{resnum} = $attr->{identifierref};
177: $$items{$itm}{title} = $attr->{title};
178: } elsif ($cms eq 'angel') {
179: if ($attr->{identifierref} =~ m/^res(.+)$/) {
180: $$items{$itm}{resnum} = $1;
181: }
182: }
1.2 raeburn 183: unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) {
184: %{$$resources{$$items{$itm}{resnum}}} = ();
1.1 raeburn 185: }
186: $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
187:
188: if ($start > @seq) {
189: unless ($lastitem eq '') {
190: push @seq, $lastitem;
191: unless ( defined($contents{$seq[-1]}) ) {
192: @{$contents{$seq[-1]}} = ();
193: }
194: push @{$contents{$seq[-1]}},$itm;
195: $$items{$itm}{parentseq} = $seq[-1];
196: }
197: }
198: elsif ($start < @seq) {
199: my $diff = @seq - $start;
200: while ($diff > 0) {
201: pop @seq;
202: $diff --;
203: }
204: if (@seq) {
205: push @{$contents{$seq[-1]}}, $itm;
206: }
207: } else {
208: push @{$contents{$seq[-1]}}, $itm;
209: }
210: my $path;
211: if (@seq > 1) {
212: $path = join(',',@seq);
213: } elsif (@seq > 0) {
214: $path = $seq[0];
215: }
216: $$items{$itm}{filepath} = $path;
1.2 raeburn 217: if ($cms eq 'bb5') {
218: if ($$items{$itm}{filepath} eq 'Top') {
219: $$items{$itm}{resnum} = $itm;
220: $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document';
221: $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
222: $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true';
223: }
224: }
1.1 raeburn 225: $$items{$seq[-1]}{contentscount} ++;
226: $lastitem = $itm;
227: }
228: } elsif ("@state" eq "manifest resources resource" ) {
229: $identifier = $attr->{identifier};
230: if ($cms eq 'bb5') {
231: $$resources{$identifier}{file} = $attr->{file};
232: $$resources{$identifier}{type} = $attr->{type};
233: } elsif ($cms eq 'angel') {
234: $identifier = substr($identifier,3);
235: if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
236: $$resources{$identifier}{file} = $1;
237: }
238: }
239: @{$$hrefs{$identifier}} = ();
240: } elsif ("@state" eq "manifest resources resource file") {
241: if ($cms eq 'bb5') {
242: push @{$$hrefs{$identifier}},$attr->{href};
243: } elsif ($cms eq 'angel') {
244: if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
245: push @{$$hrefs{$identifier}},$1;
246: } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
247: $$resources{$identifier}{type} = $1;
248: }
249: }
250: }
251: }, "tagname, attr"],
252: text_h =>
253: [sub {
254: my ($text) = @_;
1.4 raeburn 255: if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq "organization" && $state[-1] eq "title") {
256: if ($cms eq 'angel') {
257: $$items{$itm}{title} = $text;
258: }
259: }
1.1 raeburn 260: }, "dtext"],
261: end_h =>
262: [sub {
263: my ($tagname) = @_;
264: pop @state;
265: }, "tagname"],
266: );
267: $p->parse_file($xmlfile);
268: $p->eof;
269:
270: foreach my $itm (keys %contents) {
271: @{$$items{$itm}{contents}} = @{$contents{$itm}};
272: }
273: return 'ok' ;
274: }
275:
276: sub target_resources {
1.2 raeburn 277: my ($resources,$oktypes,$targets) = @_;
1.1 raeburn 278: foreach my $key (keys %{$resources}) {
279: if ( defined($$oktypes{$$resources{$key}{type}}) ) {
280: push @{$targets}, $key;
281: }
282: }
283: return;
284: }
285:
286: sub copy_resources {
1.2 raeburn 287: my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$chome,$destdir,$timenow) = @_;
1.1 raeburn 288: if ($context eq 'DOCS') {
289: foreach my $key (sort keys %{$hrefs}) {
290: if (grep/^$key$/,@{$targets}) {
1.2 raeburn 291: %{$$url{$key}} = ();
1.1 raeburn 292: foreach my $file (@{$$hrefs{$key}}) {
1.2 raeburn 293: my $source = $tempdir.'/'.$key.'/'.$file;
294: my $filename = '';
1.3 raeburn 295: my $fpath = $timenow.'/resfiles/'.$key.'/';
296: if ($cms eq 'angel') {
297: if ($file eq 'pg'.$key.'.htm') {
298: next;
1.1 raeburn 299: }
300: }
1.3 raeburn 301: $file =~ s-\\-/-g;
302: $file = $fpath.$file;
303: my $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$chome,$file,$source);
1.1 raeburn 304: }
305: }
306: }
307: } elsif ($context eq 'CSTR') {
308: if (!-e "$destdir/resfiles") {
1.2 raeburn 309: mkdir("$destdir/resfiles",0770);
1.1 raeburn 310: }
1.2 raeburn 311: foreach my $key (sort keys %{$hrefs}) {
312: foreach my $file (@{$$hrefs{$key}}) {
313: $file =~ s-\\-/-g;
314: if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') ) {
315: if (!-e "$destdir/resfiles/$key") {
316: mkdir("$destdir/resfiles/$key",0770);
1.1 raeburn 317: }
1.2 raeburn 318:
1.1 raeburn 319: my $filepath = $file;
1.2 raeburn 320: my $front = '';
1.1 raeburn 321: while ($filepath =~ m-(\w+)/(.+)-) {
1.2 raeburn 322: $front .= $1.'/';
1.1 raeburn 323: $filepath = $2;
1.2 raeburn 324: my $fulldir = "$destdir/resfiles/$key/$front";
325: chop($fulldir);
326: if (!-e "$fulldir") {
327: mkdir("$fulldir",0770);
328: }
329: }
330: if ($cms eq 'angel') {
331: rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
332: } elsif ($cms eq 'bb5') {
333: rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
334: }
335: }
336: }
337: }
338: }
339: }
340:
1.3 raeburn 341: sub process_coursefile {
342: my ($crs,$cdom,$chome,$file,$source)=@_;
343: my $fetchresult = '';
344: my $fpath = '';
345: my $fname = $file;
346: ($fpath,$fname) = ($file =~ m/^(.*)\/([^\/])$/);
347: $fpath=$cdom.'/'.$crs.'/'.$fpath;
348: my $filepath=$Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
349: unless ($fpath eq '') {
350: my @parts=split(/\//,$fpath);
351: foreach my $part (@parts) {
352: $filepath.= '/'.$part;
353: if ((-e $filepath)!=1) {
354: mkdir($filepath,0777);
355: }
356: }
357: }
358: if ($source eq '') {
359: $fetchresult eq 'no source file provided';
360: } else {
361: my $destination = $filepath.'/'.$fname;
362: rename($source,$destination);
363: $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$file,$chome);
364: unless ($fetchresult eq 'ok') {
365: &Apache::lonnet::logthis('Failed to transfer '.$cdom.'/'.$crs.'/'.$fname.' to host '.$chome.': '.$fetchresult);
366: }
367: }
368: return $fetchresult;
369: }
370:
1.2 raeburn 371: sub process_resinfo {
1.7 raeburn 372: my ($cms,$context,$docroot,$destdir,$items,$resources,$boards,$announcements,$quizzes,$surveys,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles) = @_;
1.2 raeburn 373: my $board_id = time;
374: my $board_count = 0;
375: my $announce_handling = 'include';
376: my $longcrs = '';
377: if ($crs =~ m/^(\d)(\d)(\d)/) {
378: $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
379: }
380: if ($cms eq 'angel') {
381: my $currboard = '';
382: foreach my $key (sort keys %{$resources}) {
383: if ($$resources{$key}{type} eq "BOARD") {
384: push @{$boards}, $key;
385: $$boardnum{$$resources{$key}{revitm}} = $board_count;
386: $currboard = $key;
387: @{$$messages{$key}} = ();
388: $$timestamp[$board_count] = $board_id;
389: $board_id ++;
390: $board_count ++;
391: } elsif ($$resources{$key}{type} eq "MESSAGE") {
392: push @{$$messages{$currboard}}, $key;
393: } elsif ($$resources{$key}{type} eq "PAGE" || $$resources{$key}{type} eq "LINK") {
394: %{$$resinfo{$key}} = ();
395: &angel_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
396: } elsif ($$resources{$key}{type} eq "QUIZ") {
397: %{$$resinfo{$key}} = ();
1.3 raeburn 398: push @{$quizzes}, $key;
1.2 raeburn 399: # &angel_assessment($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
400: } elsif ($$resources{$key}{type} eq "FORM") {
401: %{$$resinfo{$key}} = ();
1.3 raeburn 402: push @{$surveys}, $key;
1.2 raeburn 403: # &angel_assessment($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
404: } elsif ($$resources{$key}{type} eq "DROPBOX") {
405: %{$$resinfo{$key}} = ();
406: }
407: }
408: } elsif ($cms eq 'bb5') {
409: foreach my $key (sort keys %{$resources}) {
410: if ($$resources{$key}{type} eq "resource/x-bb-document") {
411: unless ($$items{$$resources{$key}{revitm}}{filepath} eq 'Top') {
1.3 raeburn 412: %{$$resinfo{$key}} = ();
1.7 raeburn 413: &process_content($key,$context,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$resrcfiles);
1.2 raeburn 414: }
415: } elsif ($$resources{$key}{type} eq "resource/x-bb-staffinfo") {
416: %{$$resinfo{$key}} = ();
417: &process_staff($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
418: } elsif ($$resources{$key}{type} eq "resource/x-bb-externallink") {
419: %{$$resinfo{$key}} = ();
420: &process_link($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
421: } elsif ($$resources{$key}{type} eq "resource/x-bb-discussionboard") {
422: %{$$resinfo{$key}} = ();
423: unless ($db_handling eq 'ignore') {
424: push @{$boards}, $key;
425: $$timestamp[$board_count] = $board_id;
426: &process_db($key,$docroot,$destdir,$board_id,$crs,$cdom,$db_handling,$uname,\%{$$resinfo{$key}},$longcrs);
427: $board_id ++;
428: $board_count ++;
429: }
430: } elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
431: %{$$resinfo{$key}} = ();
432: &process_assessment($key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname);
433: } elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") {
434: %{$$resinfo{$key}} = ();
435: &process_assessment($key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname);
436: push @{$quizzes}, $key;
437: } elsif ($$resources{$key}{type} eq "assessment/x-bb-survey") {
438: %{$$resinfo{$key}} = ();
439: &process_assessment($key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname);
440: push @{$surveys}, $key;
441: } elsif ($$resources{$key}{type} eq "assessment/x-bb-group") {
442: %{$$resinfo{$key}} = ();
443: push @{$groups}, $key;
444: &process_group($key,$docroot,$destdir,\%{$$resinfo{$key}});
445: } elsif ($$resources{$key}{type} eq "resource/x-bb-user") {
446: %{$$resinfo{$key}} = ();
447: unless ($user_handling eq 'ignore') {
448: &process_user($key,$docroot,$destdir,\%{$$resinfo{$key}},$crs,$cdom,$user_handling);
449: }
450: } elsif ($$resources{$key}{type} eq "resource/x-bb-announcement") {
451: unless ($announce_handling eq 'ignore') {
452: push @{$announcements}, $key;
453: %{$$resinfo{$key}} = ();
1.3 raeburn 454: &process_announce($key,$docroot,$destdir,\%{$$resinfo{$key}},$resinfo,$seqstem,$resrcfiles);
1.2 raeburn 455: }
456: }
457: }
1.3 raeburn 458: if (@{$announcements}) {
459: $$items{'Top'}{'contentscount'} ++;
460: }
461: if (@{$boards}) {
462: $$items{'Top'}{'contentscount'} ++;
463: }
464: if (@{$quizzes}) {
465: $$items{'Top'}{'contentscount'} ++;
466: }
467: if (@{$surveys}) {
468: $$items{'Top'}{'contentscount'} ++;
469:
470: }
1.2 raeburn 471: }
1.3 raeburn 472:
1.2 raeburn 473: $$total{'board'} = $board_count;
1.3 raeburn 474: $$total{'quiz'} = @{$quizzes};
475: $$total{'surv'} = @{$surveys};
1.2 raeburn 476: }
477:
478: sub build_structure {
1.3 raeburn 479: my ($cms,$context,$destdir,$items,$resinfo,$resources,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames) = @_;
1.2 raeburn 480: my %flag = ();
481: my %count = ();
482: my %pagecontents = ();
483: my %seqtext = ();
484: my $topnum = 0;
485:
486: if (!-e "$destdir") {
487: mkdir("$destdir",0755);
488: }
489: if (!-e "$destdir/sequences") {
490: mkdir("$destdir/sequences",0770);
491: }
492: if (!-e "$destdir/resfiles") {
493: mkdir("$destdir/resfiles",0770);
494: }
495: if (!-e "$destdir/pages") {
496: mkdir("$destdir/pages",0770);
497: }
498: if (!-e "$destdir/problems") {
499: mkdir("$destdir/problems",0770);
500: }
501:
502: $seqtext{'Top'} = qq|<map>\n|;
503: %{$$resinfo{$$items{'Top'}{resnum}}} = (
504: isfolder => 'true',
505: );
506:
507: my $srcstem = "";
508:
509: if ($context eq 'DOCS') {
510: $srcstem = "/uploaded/$cdom/$crs/$timenow";
511: } elsif ($context eq 'CSTR') {
512: $srcstem = "/res/$udom/$uname/$newdir";
513: }
514:
515: foreach my $key (sort keys %{$items}) {
516: %{$flag{$key}} = (
517: page => 0,
518: seq => 0,
519: board => 0,
520: file => 0,
521: );
522:
523: %{$count{$key}} = (
524: page => -1,
525: seq => 0,
526: board => 0,
527: file => 0,
528: );
529:
530: my $src = "";
531:
532: my $next_id = 2;
533: my $curr_id = 1;
534: my $resnum = $$items{$key}{resnum};
535: my $type = $$resources{$resnum}{type};
536: if (($cms eq 'angel' && $type eq "FOLDER") || ($cms eq 'bb5' && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) ) {
537: unless ($cms eq 'bb5' && $key eq 'Top') {
538: $seqtext{$key} = "<map>\n";
539: }
540: if ($$items{$key}{contentscount} == 0) {
541: $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
542: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
543: <resource id="$next_id" src="" type="finish"></resource>\n|;
544: } else {
545: my $contcount = @{$$items{$key}{contents}};
546: my $contitem = $$items{$key}{contents}[0];
547: my $res = $$items{$contitem}{resnum};
548: my $type = $$resources{$res}{type};
549: my $title = $$items{$contitem}{title};
550: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom);
551: unless ($flag{$key}{page} == 1) {
1.5 raeburn 552: $seqtext{$key} .= qq|<resource id="$curr_id" src="$src" title="$title" type="start"|;
1.2 raeburn 553: unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) {
554: $flag{$key}{page} = 1;
555: }
556: if ($key eq 'Top') {
557: push @{$topurls}, $src;
558: push @{$topnames}, $title;
559: }
560: }
561: if ($contcount == 1) {
562: $seqtext{$key} .= qq|></resource>
563: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
564: <resource id="$next_id" src="" type="finish"></resource>\n|;
565: } else {
566: if ($contcount > 2 ) {
567: for (my $i=1; $i<$contcount-1; $i++) {
568: my $contitem = $$items{$key}{contents}[$i];
569: my $res = $$items{$contitem}{resnum};
570: my $type = $$resources{$res}{type};
571: my $title = $$items{$contitem}{title};
572: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom);
573: unless ($flag{$key}{page} == 1) {
574: $seqtext{$key} .= qq|></resource>
575: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
576: <resource id="$next_id" src="$src" title="$title"|;
577: $curr_id ++;
578: $next_id ++;
579: unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) {
580: $flag{$key}{page} = 1;
581: }
582: if ($key eq 'Top') {
583: push @{$topurls}, $src;
584: push @{$topnames}, $title;
585: }
586: }
587: }
588: }
589: my $contitem = $$items{$key}{contents}[-1];
590: my $res = $$items{$contitem}{resnum};
591: my $type = $$resources{$res}{type};
592: my $title = $$items{$contitem}{title};
593:
594: $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom);
595: if ($flag{$key}{page}) {
596: if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) {
597: $seqtext{$key} .= qq|></resource>
598: <link from="$curr_id" index="$curr_id" to="$next_id">
599: <resource id ="$next_id" src="" |;
600: }
601: } else {
602: $seqtext{$key} .= qq|></resource>
603: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
604: <resource id="$next_id" src="$src" title="$title" |;
605: if ($key eq 'Top') {
606: push @{$topurls}, $src;
607: push @{$topnames}, $title;
608: }
609: }
610: if ($contcount == $$items{$key}{contentscount}) {
611: $seqtext{$key} .= qq|type="finish"></resource>\n|;
612: } else {
613: $curr_id ++;
614: $next_id ++;
615: $seqtext{$key} .= qq|></resource>
1.8 raeburn 616: <link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|;
1.2 raeburn 617: }
618: }
619: }
620: unless ($cms eq 'bb5' && $key eq 'Top') {
621: $seqtext{$key} .= "</map>\n";
622: open(LOCFILE,">$destdir/sequences/$key.sequence");
623: print LOCFILE $seqtext{$key};
624: close(LOCFILE);
625: push @{$seqfiles}, "$key.sequence";
626: }
627: $count{$key}{page} ++;
628: $$total{page} += $count{$key}{page};
629: }
630: $$total{seq} += $count{$key}{seq};
631: }
632: $topnum += ($count{'Top'}{page} + $count{'Top'}{seq});
633:
634: if ($cms eq 'bb5') {
635: if (@{$announcements} > 0) {
636: &process_specials($context,'announcements',$announcements,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
637: }
638: if (@{$boards} > 0) {
639: &process_specials($context,'boards',$boards,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
640: }
641: if (@{$quizzes} > 0) {
642: &process_specials($context,'quizzes',$quizzes,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
643: }
644: if (@{$surveys} > 0) {
645: &process_specials($context,'surveys',$surveys,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
646: }
647:
648: $seqtext{'Top'} .= "</map>\n";
649: open(TOPFILE,">$destdir/sequences/Top.sequence");
650: print TOPFILE $seqtext{'Top'};
651: close(TOPFILE);
652: push @{$seqfiles}, 'Top.sequence';
653: }
654:
655: my $filestem;
656: if ($context eq 'DOCS') {
1.6 raeburn 657: $filestem = "/uploaded/$cdom/$crs/$timenow";
1.2 raeburn 658: } elsif ($context eq 'CSTR') {
659: $filestem = "/res/$udom/$uname/$newdir";
660: }
661:
662: foreach my $key (sort keys %pagecontents) {
663: for (my $i=0; $i<@{$pagecontents{$key}}; $i++) {
664: my $filename = $destdir.'/pages/'.$key.'_'.$i.'.page';
665: open(PAGEFILE,">$filename");
666: print PAGEFILE qq|<map>
1.3 raeburn 667: <resource src="$filestem/resfiles/$$items{$pagecontents{$key}[$i][0]}{resnum}.html" id="1" type="start" title="$$items{$pagecontents{$key}[$i][0]}{title}"></resource>
1.2 raeburn 668: <link to="2" index="1" from="1">\n|;
669: if (@{$pagecontents{$key}[$i]} == 1) {
1.3 raeburn 670: print PAGEFILE qq|<resource src="" id="2" type="finish"></resource>\n|;
1.2 raeburn 671: } elsif (@{$pagecontents{$key}[$i]} == 2) {
1.3 raeburn 672: print PAGEFILE qq|<resource src="$filestem/resfiles/$$items{$pagecontents{$key}[$i][1]}{resnum}.html" id="2" type="finish" title="$$items{$pagecontents{$key}[$i][1]}{title}"></resource>\n|;
1.2 raeburn 673: } else {
674: for (my $j=1; $j<@{$pagecontents{$key}[$i]}-1; $j++) {
675: my $curr_id = $j+1;
676: my $next_id = $j+2;
677: my $resource = $filestem.'/resfiles/'.$$items{$pagecontents{$key}[$i][$j]}{resnum}.'.html';
678: print PAGEFILE qq|<resource src="$resource" id="$curr_id" title="$$items{$pagecontents{$key}[$i][$j]}{title}"></resource>
679: <link to="$next_id" index="$curr_id" from="$curr_id">\n|;
680: }
681: my $final_id = @{$pagecontents{$key}[$i]};
1.3 raeburn 682: print PAGEFILE qq|<resource src="$filestem/resfiles/$$items{$pagecontents{$key}[$i][-1]}{resnum}.html" id="$final_id" type="finish" title="$$items{$pagecontents{$key}[$i][-1]}{title}"></resource>\n|;
1.2 raeburn 683: }
684: print PAGEFILE "</map>";
685: close(PAGEFILE);
686: push @{$pagesfiles}, $key.'_'.$i.'.page';
687: }
688: }
689: }
690:
691: sub make_structure {
692: my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom) = @_;
693: my $src ='';
694: if (($cms eq 'angel' && $type eq 'FOLDER') || ($cms eq 'bb5' && ($$resinfo{$res}{'isfolder'} eq 'true') || ($key eq 'Top')) ) {
695: $src = $srcstem.'/sequences/'.$contitem.'.sequence';
696: $$flag{$key}{page} = 0;
697: $$flag{$key}{seq} = 1;
698: $$count{$key}{seq} ++;
699: } elsif ($cms eq 'angel' && $type eq 'BOARD') {
700: $src = '/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$$boardnum{$res}].'/bulletinboard';
701: $$flag{$key}{page} = 0;
702: $$flag{$key}{board} = 1;
703: $$count{$key}{board} ++;
704: } elsif ($cms eq 'angel' && $type eq "FILE") {
705: foreach my $file (@{$$hrefs{$res}}) {
706: unless ($file eq 'pg'.$res.'.htm') {
707: $src = $srcstem.'/resfiles/'.$res.'/'.$file;
708: }
709: }
710: $$flag{$key}{page} = 0;
711: $$flag{$key}{file} = 1;
712: } elsif ($cms eq 'angel' && (($type eq "PAGE") || ($type eq "LINK")) ) {
713: if ($$flag{$key}{page}) {
1.3 raeburn 714: if ($$count{$key}{page} == -1) {
715: print STDERR "Array index is -1, we shouldnt be here, key is $key, type is $type\n";
1.2 raeburn 716: } else {
717: push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem;
718: }
719: } else {
720: $$count{$key}{page} ++;
721: $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page';
722: @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem");
723: $$flag{$key}{seq} = 0;
724: }
725: } elsif ($cms eq 'bb5') {
726: if ($$flag{$key}{page}) {
727: push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem;
728: } else {
729: $$count{$key}{page} ++;
730: $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page';
731: @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem");
732: $$flag{$key}{seq} = 0;
733: }
734: }
735: return $src;
736: }
737:
738:
739: # ---------------------------------------------------------------- Process Blackboard specials - announcements, bulletin boards, quizzes and surveys
740: sub process_specials {
741: my ($context,$type,$specials,$topnum,$contentscount,$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,$seqtext,$pagesfiles,$seqfiles,$topurls,$topnames) = @_;
742: my $src = '';
743: my $specialsrc = '';
744: my $nextnum = 0;
745: my $seqstem = '';
746: if ($context eq 'CSTR') {
1.3 raeburn 747: $seqstem = "/res/$udom/$uname/$newdir";
1.2 raeburn 748: } elsif ($context eq 'DOCS') {
749: $seqstem = '/uploaded/'.$cdom.'/'.$crs.'/'.$timenow;
750: }
751: my %seqnames = (
752: boards => 'bulletinboards',
753: quizzes => 'quizzes',
754: surveys => 'surveys',
755: announcements => 'announcements',
756: );
757: my %seqtitles = (
758: boards => 'Course Bulletin Boards',
759: quizzes => 'Course Quizzes',
760: surveys => 'Course Surveys',
761: announcements => 'Course Announcements',
762: );
763: $$topnum ++;
764:
765: if ($type eq 'announcements') {
766: $src = "$seqstem/pages/$seqnames{$type}.page";
767: } else {
768: $src = "$seqstem/sequences/$seqnames{$type}.sequence";
769: }
770:
771: push @{$topurls}, $src;
772: push @{$topnames}, $seqtitles{$type};
773:
774: $$seqtext .= qq|<resource id="$$topnum" src="$src" title="$seqtitles{$type}"|;
775: $nextnum = $$topnum +1;
776: if ($$topnum == 1) {
777: $$seqtext .= qq| type="start"></resource>
778: <link from="$$topnum" to="$nextnum" index="$$topnum"></link>\n|;
779: if ($$topnum == $contentscount) {
780: $$seqtext .= qq|<resource id="$nextnum" src="" type="finish"></resource>\n|;
781: }
782: } else {
783: if ($$topnum == $contentscount) {
784: $$seqtext .= qq| type="finish"></resource>\n|;
785: } else {
786: $$seqtext .= qq|></resource>
787: <link from="$$topnum" to="$nextnum" index="$$topnum"></link>\n|;
788: }
789: }
790:
791: if ($type eq "announcements") {
792: push @{$pagesfiles}, "$seqnames{$type}.page";
793: open(ITEM,">$destdir/pages/$seqnames{$type}.page");
794: } else {
795: push @{$seqfiles}, "$seqnames{$type}.sequence";
796: open(ITEM,">$destdir/sequences/$seqnames{$type}.sequence");
797: }
798:
799: if ($type eq 'boards') {
800: $specialsrc = "/adm/$udom/$uname/$$timestamp[0]/bulletinboard";
801: } elsif ($type eq 'announcements') {
802: $specialsrc = "$seqstem/resfiles/$$specials[0].html";
803: } else {
804: $specialsrc = "$seqstem/pages/$$specials[0].page";
805: }
806: print ITEM qq|<map>
807: <resource id="1" src="$specialsrc" title="$$resinfo{$$specials[0]}{title}" type="start"></resource>
808: <link from="1" to="2" index="1"></link>|;
809: if (@{$specials} == 1) {
810: print ITEM qq|
811: <resource id="2" src="" type="finish"></resource>\n|;
812: } else {
813: for (my $i=1; $i<@{$specials}; $i++) {
814: my $curr = $i+1;
815: my $next = $i+2;
816: if ($type eq 'boards') {
817: $specialsrc = "/adm/$udom/$uname/$$timestamp[$i]/bulletinboard";
818: } elsif ($type eq 'announcements') {
819: $specialsrc = "$seqstem/resfiles/$$specials[$i].html";
820: } else {
821: $specialsrc = "$seqstem/pages/$$specials[$i].page";
822: }
823: print ITEM qq|<resource id="$curr" src="$specialsrc" title="$$resinfo{$$specials[$i]}{title}"|;
824: if (@{$specials} == $i+1) {
825: print ITEM qq| type="finish"></resource>\n|;
826: } else {
827: print ITEM qq|></resource>
828: <link from="$curr" to="$next" index="$next">\n|;
829: }
830: }
831: }
832: print ITEM qq|</map>|;
833: close(ITEM);
834: }
835:
836: # ---------------------------------------------------------------- Process Blackboard users
837: sub process_user {
838: my ($res,$docroot,$destdir,$settings,$user_crs,$user_cdom,$user_handling) = @_;
839: my $xmlfile = $docroot.'/'.$res.".dat";
840: my $filecount = 0;
841: my @state;
842: my $userid = '';
843: my $linknum = 0;
844:
845: my $p = HTML::Parser->new
846: (
847: xml_mode => 1,
848: start_h =>
849: [sub {
850: my ($tagname, $attr) = @_;
851: push @state, $tagname;
1.7 raeburn 852: if ("@state" eq "USERS USER") {
1.2 raeburn 853: $userid = $attr->{value};
854: %{$$settings{$userid}} = ();
855: @{$$settings{$userid}{links}} = ();
1.7 raeburn 856: } elsif ("@state" eq "USERS USER LOGINID") {
1.2 raeburn 857: $$settings{$userid}{loginid} = $attr->{value};
1.7 raeburn 858: } elsif ("@state" eq "USERS USER PASSPHRASE") {
1.2 raeburn 859: $$settings{$userid}{passphrase} = $attr->{value};
860: } elsif ("@state" eq "USERS USER STUDENTID" ) {
861: $$settings{$userid}{studentid} = $attr->{value};
862: } elsif ("@state" eq "USERS USER NAMES FAMILY" ) {
863: $$settings{$userid}{family} = $attr->{value};
864: } elsif ("@state" eq "USERS USER NAMES GIVEN" ) {
865: $$settings{$userid}{given} = $attr->{value};
866: } elsif ("@state" eq "USERS USER ADDRESSES BUSINESS DATA EMAIL") {
867: $$settings{$userid}{email} = $attr->{value};
868: } elsif ("@state" eq "USERS USER USER_ROLE") {
869: $$settings{$userid}{user_role} = $attr->{value};
870: } elsif ("@state" eq "USERS USER FLAGS ISAVAILABLE") {
871: $$settings{$userid}{isavailable} = $attr->{value};
872: } elsif ("@state" eq "USERS USER PERSONALPAGE FILELIST IMAGE") {
873: $$settings{$userid}{image} = $attr->{value};
874: } elsif ( ($state[-2] eq "LINKLIST") && ($state[-1] eq "LINK") ) {
875: %{$$settings{$userid}{links}[$linknum]} = ();
876: $$settings{$userid}{links}[$linknum]{url} = $attr->{value};
877: $linknum ++;
878: }
879: }, "tagname, attr"],
880: text_h =>
881: [sub {
882: my ($text) = @_;
883: if ("@state" eq "USERS USER PERSONALPAGE TITLE") {
884: $$settings{$userid}{title} = $text;
885: } elsif ("@state" eq "USERS USER PERSONALPAGE DESCRIPTION") {
886: $$settings{$userid}{description} = $text;
887: } elsif (($state[-2] eq "LINK") && ($state[-1] eq "TITLE")) {
888: $$settings{$userid}{links}[$linknum]{title} = $text;
889: } elsif (($state[-3] eq "LINK") && ($state[-2] eq "DESCRIPTION") && ($state[-1] eq "TEXT")) {
890: $$settings{$userid}{links}[$linknum]{text} = $text;
891: }
892: }, "dtext"],
893: end_h =>
894: [sub {
895: my ($tagname) = @_;
1.7 raeburn 896: if ("@state" eq "USERS USER") {
1.2 raeburn 897: $linknum = 0;
898: }
899: pop @state;
900: }, "tagname"],
901: );
902: $p->unbroken_text(1);
903: $p->parse_file($xmlfile);
904: $p->eof;
905:
906: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
907: my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$user_cdom."_".$user_crs."_";
908:
909: foreach my $user_id (keys %{$settings}) {
910: if ($$settings{$user_id}{user_role} eq "s") {
911:
912: } elsif ($user_handling eq 'enrollall') {
913:
914: }
915: }
916: }
917:
918: # ---------------------------------------------------------------- Process Blackboard groups
919: sub process_group {
920: my ($res,$docroot,$destdir,$settings) = @_;
921: my $xmlfile = $docroot.'/'.$res.".dat";
922: my $filecount = 0;
923: my @state;
924: my $grp;
925:
926: my $p = HTML::Parser->new
927: (
928: xml_mode => 1,
929: start_h =>
930: [sub {
931: my ($tagname, $attr) = @_;
932: push @state, $tagname;
1.7 raeburn 933: if ("@state" eq "GROUPS GROUP") {
1.2 raeburn 934: $grp = $attr->{id};
935: }
1.7 raeburn 936: if ("@state" eq "GROUPS GROUP TITLE") {
1.2 raeburn 937: $$settings{$grp}{title} = $attr->{value};
1.7 raeburn 938: } elsif ("@state" eq "GROUPS GROUP FLAGS ISAVAILABLE") {
1.2 raeburn 939: $$settings{$grp}{isavailable} = $attr->{value};
1.7 raeburn 940: } elsif ("@state" eq "GROUPS GROUP FLAGS HASCHATROOM") {
1.2 raeburn 941: $$settings{$grp}{chat} = $attr->{value};
942: } elsif ("@state" eq "GROUPS GROUP FLAGS HASDISCUSSIONBOARD") {
943: $$settings{$grp}{discussion} = $attr->{value};
944: } elsif ("@state" eq "GROUPS GROUP FLAGS HASTRANSFERAREA") {
945: $$settings{$grp}{transfer} = $attr->{value};
946: } elsif ("@state" eq "GROUPS GROUP FLAGS ISPUBLIC") {
947: $$settings{$grp}{public} = $attr->{value};
948: }
949: }, "tagname, attr"],
950: text_h =>
951: [sub {
952: my ($text) = @_;
953: if ("@state" eq "GROUPS DESCRIPTION") {
954: $$settings{$grp}{description} = $text;
955: # print "Staff text is $text\n";
956: }
957: }, "dtext"],
958: end_h =>
959: [sub {
960: my ($tagname) = @_;
961: pop @state;
962: }, "tagname"],
963: );
964: $p->unbroken_text(1);
965: $p->parse_file($xmlfile);
966: $p->eof;
967: }
968:
969: # ---------------------------------------------------------------- Process Blackboard Staff
970: sub process_staff {
971: my ($res,$docroot,$dirname,$destdir,$settings,$resrcfiles) = @_;
972: my $xmlfile = $docroot.'/'.$res.".dat";
973: my $filecount = 0;
974: my @state;
975: %{$$settings{name}} = ();
976: %{$$settings{office}} = ();
977:
978: my $p = HTML::Parser->new
979: (
980: xml_mode => 1,
981: start_h =>
982: [sub {
983: my ($tagname, $attr) = @_;
984: push @state, $tagname;
1.7 raeburn 985: if ("@state" eq "STAFFINFO TITLE") {
1.2 raeburn 986: $$settings{title} = $attr->{value};
1.7 raeburn 987: } elsif ("@state" eq "STAFFINFO BIOGRAPHY TEXTCOLOR") {
1.2 raeburn 988: $$settings{textcolor} = $attr->{value};
1.7 raeburn 989: } elsif ("@state" eq "STAFFINFO BIOGRAPHY FLAGS ISHTML") {
1.2 raeburn 990: $$settings{ishtml} = $attr->{value};
991: } elsif ("@state" eq "STAFFINFO FLAGS ISAVAILABLE" ) {
992: $$settings{isavailable} = $attr->{value};
993: } elsif ("@state" eq "STAFFINFO FLAGS ISFOLDER" ) {
994: $$settings{isfolder} = $attr->{value};
995: } elsif ("@state" eq "STAFFINFO POSITION" ) {
996: $$settings{position} = $attr->{value};
997: } elsif ("@state" eq "STAFFINFO HOMEPAGE" ) {
998: $$settings{homepage} = $attr->{value};
999: } elsif ("@state" eq "STAFFINFO IMAGE") {
1000: $$settings{image} = $attr->{value};
1001: }
1002: }, "tagname, attr"],
1003: text_h =>
1004: [sub {
1005: my ($text) = @_;
1006: if ("@state" eq "STAFFINFO BIOGRAPHY TEXT") {
1007: $$settings{text} = $text;
1008: # print "Staff text is $text\n";
1009: } elsif ("@state" eq "STAFFINFO CONTACT PHONE") {
1010: $$settings{phone} = $text;
1011: } elsif ("@state" eq "STAFFINFO CONTACT EMAIL") {
1012: $$settings{email} = $text;
1013: } elsif ("@state" eq "STAFFINFO CONTACT NAME FORMALTITLE") {
1014: $$settings{name}{formaltitle} = $text;
1015: } elsif ("@state" eq "STAFFINFO CONTACT NAME FAMILY") {
1016: $$settings{name}{family} = $text;
1017: } elsif ("@state" eq "STAFFINFO CONTACT NAME GIVEN") {
1018: $$settings{name}{given} = $text;
1019: } elsif ("@state" eq "STAFFINFO CONTACT OFFICE HOURS") {
1020: $$settings{office}{hours} = $text;
1021: } elsif ("@state" eq "STAFFINFO CONTACT OFFICE ADDRESS") {
1022: $$settings{office}{address} = $text;
1023: }
1024: }, "dtext"],
1025: end_h =>
1026: [sub {
1027: my ($tagname) = @_;
1028: pop @state;
1029: }, "tagname"],
1030: );
1031: $p->unbroken_text(1);
1032: $p->parse_file($xmlfile);
1033: $p->eof;
1034:
1035: my $fontcol = '';
1036: if (defined($$settings{textcolor})) {
1037: $fontcol = qq|color="$$settings{textcolor}"|;
1038: }
1039: if (defined($$settings{text})) {
1040: if ($$settings{ishtml} eq "true") {
1041: $$settings{text} = &HTML::Entities::decode($$settings{text});
1042: }
1043: }
1044: my $staffentry = qq|
1045: <table border="0" cellpadding="0" cellspacing="0" width="100%">
1046: <tr>
1047: <td colspan="2"><hr /><font face="arial,helv" size="3"><b>$$settings{name}{formaltitle} $$settings{name}{given} $$settings{name}{family}</b></font>
1048: </td>
1049: </tr>
1050: <tr>
1051: <td valign="top">
1052: <table width="100% border="0" cols="2" cellpadding="0" cellspacing="0">|;
1053: if ( defined($$settings{email}) && $$settings{email} ne '') {
1054: $staffentry .= qq|
1055: <tr>
1056: <td width="100" valign="top">
1057: <font face="arial" size="2"><b>Email:</b></font>
1058: </td>
1059: <td>
1060: <font face="arial" size="2"><a href="mailto:$$settings{email}">$$settings{email}</a></font>
1061: </td>
1062: </tr>
1063: |;
1064: }
1065: if (defined($$settings{phone}) && $$settings{phone} ne '') {
1066: $staffentry .= qq|
1067: <tr>
1068: <td width="100" valign="top">
1069: <font face="arial" size="2"><b>Phone:</b></font>
1070: </td>
1071: <td>
1072: <font face="arial" size="2">$$settings{phone}</font>
1073: </td>
1074: </tr>
1075: |;
1076: }
1077: if (defined($$settings{office}{address}) && $$settings{office}{address} ne '') {
1078: $staffentry .= qq|
1079: <tr>
1080: <td width="100" valign="top">
1081: <font face="arial" size="2"><b>Address:</b></font>
1082: </td>
1083: <td>
1084: <font face="arial" size="2">$$settings{office}{address}</font>
1085: </td>
1086: </tr>
1087: |;
1088: }
1089: if (defined($$settings{office}{hours}) && $$settings{office}{hours} ne '') {
1090: $staffentry .= qq|
1091: <tr>
1092: <td width="100" valign="top">
1093: <font face="arial" size="2"><b>Office Hours:</b></font>
1094: </td>
1095: <td>
1096: <font face=arial size=2>$$settings{office}{hours}</font>
1097: </td>
1098: </tr>
1099: |;
1100: }
1101: if ( defined($$settings{homepage}) && $$settings{homepage} ne '') {
1102: $staffentry .= qq|
1103: <tr>
1104: <td width="100" valign="top">
1105: <font face="arial" size="2"><b>Personal Link:</b></font>
1106: </td>
1107: <td>
1108: <font face="arial" size="2"><a href="$$settings{homepage}">$$settings{homepage}</a></font>
1109: </td>
1110: </tr>
1111: |;
1112: }
1113: if (defined($$settings{text}) && $$settings{text} ne '') {
1114: $staffentry .= qq|
1115: <tr>
1116: <td colspan="2">
1117: <font face="arial" size="2" $fontcol><b>Other Information:</b><br/>$$settings{text}</font>
1118: </td>
1119: </tr>
1120: |;
1121: }
1122: $staffentry .= qq|
1123: </table>
1124: </td>
1125: <td align="right" valign="top">
1126: |;
1127: if ( defined($$settings{image}) ) {
1128: $staffentry .= qq|
1129: <img src="$dirname/resfiles/$res/$$settings{image}">
1130: |;
1131: }
1132: $staffentry .= qq|
1133: </td>
1134: </tr>
1135: </table>
1136: |;
1137: open(FILE,">$destdir/resfiles/$res.html");
1138: push @{$resrcfiles}, "$res.html";
1139: print FILE qq|<html>
1140: <head>
1141: <title>$$settings{title}</title>
1142: </head>
1143: <body bgcolor='#ffffff'>
1144: $staffentry
1145: </body>
1146: </html>|;
1147: close(FILE);
1148: }
1149:
1150: # ---------------------------------------------------------------- Process Blackboard Links
1151: sub process_link {
1152: my ($res,$docroot,$dirname,$destdir,$settings,$resrcfiles) = @_;
1153: my $xmlfile = $docroot.'/'.$res.".dat";
1154: my @state = ();
1155: my $p = HTML::Parser->new
1156: (
1157: xml_mode => 1,
1158: start_h =>
1159: [sub {
1160: my ($tagname, $attr) = @_;
1161: push @state, $tagname;
1.7 raeburn 1162: if ("@state" eq "EXTERNALLINK TITLE") {
1.2 raeburn 1163: $$settings{title} = $attr->{value};
1.7 raeburn 1164: } elsif ("@state" eq "EXTERNALLINK TEXTCOLOR") {
1.2 raeburn 1165: $$settings{textcolor} = $attr->{value};
1.7 raeburn 1166: } elsif ("@state" eq "EXTERNALLINK DESCRIPTION FLAGS ISHTML") {
1.2 raeburn 1167: $$settings{ishtml} = $attr->{value};
1168: } elsif ("@state" eq "EXTERNALLINK FLAGS ISAVAILABLE" ) {
1169: $$settings{isavailable} = $attr->{value};
1170: } elsif ("@state" eq "EXTERNALLINK FLAGS LAUNCHINNEWWINDOW" ) {
1171: $$settings{newwindow} = $attr->{value};
1172: } elsif ("@state" eq "EXTERNALLINK FLAGS ISFOLDER" ) {
1173: $$settings{isfolder} = $attr->{value};
1174: } elsif ("@state" eq "EXTERNALLINK POSITION" ) {
1175: $$settings{position} = $attr->{value};
1176: } elsif ("@state" eq "EXTERNALLINK URL" ) {
1.7 raeburn 1177: $$settings{url} = $attr->{value};
1.2 raeburn 1178: }
1179: }, "tagname, attr"],
1180: text_h =>
1181: [sub {
1182: my ($text) = @_;
1183: if ("@state" eq "EXTERNALLINK DESCRIPTION TEXT") {
1184: $$settings{text} = $text;
1185: }
1186: }, "dtext"],
1187: end_h =>
1188: [sub {
1189: my ($tagname) = @_;
1190: pop @state;
1191: }, "tagname"],
1192: );
1193: $p->unbroken_text(1);
1194: $p->parse_file($xmlfile);
1195: $p->eof;
1196:
1197: my $linktag = '';
1198: my $fontcol = '';
1199: if (defined($$settings{textcolor})) {
1200: $fontcol = qq|<font color="$$settings{textcolor}">|;
1201: }
1202: if (defined($$settings{text})) {
1203: if ($$settings{ishtml} eq "true") {
1204: $$settings{text} = &HTML::Entities::decode($$settings{text});
1205: }
1206: }
1207:
1208: if (defined($$settings{url}) ) {
1209: $linktag = qq|<a href="$$settings{url}"|;
1210: if ($$settings{newwindow} eq "true") {
1211: $linktag .= qq| target="launch"|;
1212: }
1213: $linktag .= qq|>$$settings{title}</a>|;
1214: }
1215:
1216: open(FILE,">$destdir/resfiles/$res.html");
1217: push @{$resrcfiles}, "$res.html";
1218: print FILE qq|<html>
1219: <head>
1220: <title>$$settings{title}</title>
1221: </head>
1222: <body bgcolor='#ffffff'>
1223: $fontcol
1224: $linktag
1225: $$settings{text}
1226: |;
1227: if (defined($$settings{textcolor})) {
1228: print FILE qq|</font>|;
1229: }
1230: print FILE qq|
1231: </body>
1232: </html>|;
1233: close(FILE);
1234: }
1235:
1236: # ---------------------------------------------------------------- Process Blackboard Discussion Boards
1237: sub process_db {
1238: my ($res,$docroot,$destdir,$timestamp,$crs,$cdom,$handling,$uname,$settings,$longcrs) = @_;
1239: my $xmlfile = $docroot.'/'.$res.".dat";
1240: my @state = ();
1241: my @allmsgs = ();
1242: my %msgidx = ();
1243: my %threads; # all threads, keyed by message ID
1244: my $msg_id; # the current message ID
1245: my %message; # the current message being accumulated for $msg_id
1246:
1247: my $p = HTML::Parser->new
1248: (
1249: xml_mode => 1,
1250: start_h =>
1251: [sub {
1252: my ($tagname, $attr) = @_;
1253: push @state, $tagname;
1254: my $depth = 0;
1255: my @seq = ();
1256: if ("@state" eq "FORUM TITLE") {
1257: $$settings{title} = $attr->{value};
1258: } elsif ("@state" eq "FORUM DESCRIPTION TEXTCOLOR") {
1259: $$settings{textcolor} = $attr->{value};
1260: } elsif ("@state" eq "FORUM DESCRIPTION FLAGS ISHTML") {
1261: $$settings{ishtml} = $attr->{value};
1262: } elsif ("@state" eq "FORUM DESCRIPTION FLAGS ISNEWLINELITERAL") {
1263: $$settings{newline} = $attr->{value};
1264: } elsif ("@state" eq "FORUM POSITION" ) {
1265: $$settings{position} = $attr->{value};
1266: } elsif ("@state" eq "FORUM FLAGS ISREADONLY") {
1267: $$settings{isreadonly} = $attr->{value};
1268: } elsif ("@state" eq "FORUM FLAGS ISAVAILABLE" ) {
1269: $$settings{isavailable} = $attr->{value};
1270: } elsif ("@state" eq "FORUM FLAGS ALLOWANONYMOUSPOSTINGS" ) {
1271: $$settings{allowanon} = $attr->{value};
1272: } elsif ( ($state[0] eq "FORUM") && ($state[1] eq "MESSAGETHREADS") && ($state[2] eq "MSG") ) {
1273: if ($state[-1] eq "MSG") {
1274: unless ($msg_id eq '') {
1275: push @{$threads{$msg_id}}, { %message };
1276: $depth = @state - 3;
1277: if ($depth > @seq) {
1278: push @seq, $msg_id;
1279: }
1280: }
1281: if ($depth < @seq) {
1282: pop @seq;
1283: }
1284: $msg_id = $attr->{id};
1285: push @allmsgs, $msg_id;
1286: $msgidx{$msg_id} = @allmsgs;
1287: %message = ();
1288: $message{depth} = $depth;
1289: if ($depth > 0) {
1290: $message{parent} = $seq[-1];
1291: } else {
1292: $message{parent} = "None";
1293: }
1294: } elsif ($state[-1] eq "TITLE") {
1295: $message{title} = $attr->{value};
1296: } elsif ( ( $state[-3] eq "MESSAGETEXT" ) && ( $state[-2] eq "FLAGS" ) && ( $state[-1] eq "ISHTML" ) ) {
1297: $message{ishtml} = $attr->{value};
1298: } elsif ( ( $state[-3] eq "MESSAGETEXT" ) && ( $state[-2] eq "FLAGS" ) && ( $state[-1] eq "ISNEWLINELITERAL" ) ) {
1299: $message{newline} = $attr->{value};
1300: } elsif ( ( $state[-2] eq "DATES" ) && ( $state[-1] eq "CREATED" ) ) {
1301: $message{created} = $attr->{value};
1302: } elsif ( $state[@state-2] eq "FLAGS") {
1303: if ($state[@state-1] eq "ISANONYMOUS") {
1304: $message{isanonymous} = $attr->{value};
1305: }
1306: } elsif ( $state[-2] eq "USER" ) {
1307: if ($state[-1] eq "USERID") {
1308: $message{userid} = $attr->{value};
1309: } elsif ($state[@state-1] eq "USERNAME") {
1310: $message{username} = $attr->{value};
1311: } elsif ($state[@state-1] eq "EMAIL") {
1312: $message{email} = $attr->{value};
1313: }
1314: } elsif ( ($state[-2] eq "FILELIST") && ($state[-1] eq "IMAGE") ) {
1315: $message{attachment} = $attr->{value};
1316: }
1317: }
1318: }, "tagname, attr"],
1319: text_h =>
1320: [sub {
1321: my ($text) = @_;
1322: if ("@state" eq "FORUM DESCRIPTION TEXT") {
1323: $$settings{text} = $text;
1324: } elsif ( ($state[0] eq "FORUM") && ($state[1] eq "MESSAGETHREADS") && ($state[2] eq "MSG") ) {
1325: if ( ($state[-2] eq "MESSAGETEXT") && ($state[-1] eq "TEXT") ){
1326: $message{text} = $text;
1327: }
1328: }
1329: }, "dtext"],
1330: end_h =>
1331: [sub {
1332: my ($tagname) = @_;
1333: if ( $state[-1] eq "MESSAGETHREADS" ) {
1334: push @{$threads{$msg_id}}, { %message };
1335: }
1336: pop @state;
1337: }, "tagname"],
1338: );
1339: $p->unbroken_text(1);
1340: $p->parse_file($xmlfile);
1341: $p->eof;
1342:
1343: if (defined($$settings{text})) {
1344: if ($$settings{ishtml} eq "false") {
1345: if ($$settings{isnewline} eq "true") {
1346: $$settings{text} =~ s#\n#<br/>#g;
1347: }
1348: } else {
1349: $$settings{text} = &HTML::Entities::decode($$settings{text});
1350: }
1351: if (defined($$settings{fontcolor}) ) {
1352: $$settings{text} = "<font color=\"".$$settings{textcolor}."\">".$$settings{text}."</font>";
1353: }
1354: }
1355: my $boardname = 'bulletinpage_'.$timestamp;
1356: my %boardinfo = (
1357: 'aaa_title' => $$settings{title},
1358: 'bbb_content' => $$settings{text},
1359: 'ccc_webreferences' => '',
1360: 'uploaded.lastmodified' => time,
1361: );
1362:
1363: my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$cdom,$crs);
1364: if ($handling eq 'importall') {
1365: foreach my $msg_id (@allmsgs) {
1366: foreach my $message ( @{$threads{$msg_id}} ) {
1367: my %contrib = (
1368: 'sendername' => $$message{userid},
1369: 'senderdomain' => $cdom,
1370: 'screenname' => '',
1371: 'plainname' => $$message{username},
1372: );
1373: unless ($$message{parent} eq 'None') {
1374: $contrib{replyto} = $msgidx{$$message{parent}};
1375: }
1376: if (defined($$message{isanonymous}) ) {
1377: if ($$message{isanonymous} eq 'true') {
1378: $contrib{'anonymous'} = 'true';
1379: }
1380: }
1381: if ( defined($$message{attachment}) ) {
1382: my $url = $$message{attachment};
1383: my $oldurl = $url;
1384: my $newurl = $url;
1385: unless ($url eq '') {
1386: $newurl =~ s/\//_/g;
1387: unless ($longcrs eq '') {
1388: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles") {
1389: mkdir("/home/httpd/lonUsers/$cdom/$longcrs/userfiles",0755);
1390: }
1391: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl") {
1392: system("cp $destdir/resfiles/$res/$$message{attachment} /home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl");
1393: }
1394: $contrib{attachmenturl} = '/uploaded/'.$cdom.'/'.$crs.'/'.$newurl;
1395: }
1396: }
1397: }
1398: if (defined($$message{title}) ) {
1399: $contrib{'message'} = $$message{title};
1400: }
1401: if (defined($$message{text})) {
1402: if ($$message{ishtml} eq "false") {
1403: if ($$message{isnewline} eq "true") {
1404: $$message{text} =~ s#\n#<br/>#g;
1405: }
1406: } else {
1407: $$message{text} = &HTML::Entities::decode($$message{text});
1408: }
1409: $contrib{'message'} .= '<br /><br />'.$$message{text};
1410: my $symb = 'bulletin___'.$timestamp.'___adm/wrapper/adm/'.$cdom.'/'.$uname.'/'.$timestamp.'/bulletinboard';
1411: my $postresult = &addposting($symb,\%contrib,$cdom,$crs);
1412: }
1413: }
1414: }
1415: }
1416: }
1417:
1418: # ---------------------------------------------------------------- Add Posting to Bulletin Board
1419: sub addposting {
1420: my ($symb,$contrib,$cdom,$crs)=@_;
1421: my $status='';
1422: if (($symb) && ($$contrib{message})) {
1423: my $crsdom = $cdom.'_'.$crs;
1424: &Apache::lonnet::store($contrib,$symb,$crsdom,$cdom,$crs);
1425: my %storenewentry=($symb => time);
1426: &Apache::lonnet::put('discussiontimes',\%storenewentry,$cdom,$crs);
1427: }
1428: my %record=&Apache::lonnet::restore('_discussion');
1429: my ($temp)=keys %record;
1430: unless ($temp=~/^error\:/) {
1431: my %newrecord=();
1432: $newrecord{'resource'}=$symb;
1433: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1434: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1435: $status = 'ok';
1436: } else {
1437: $status.='Failed.';
1438: }
1439: return $status;
1440: }
1441: # ---------------------------------------------------------------- Process Blackboard Assessments - pools, quizzes, surveys
1442: sub process_assessment {
1443: my ($res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname) = @_;
1444: my $xmlfile = $docroot.'/'.$res.".dat";
1445: # print "XML file is $xmlfile\n";
1446: my @state = ();
1447: my @allids = ();
1448: my %allanswers = ();
1449: my %allchoices = ();
1450: my $resdir = '';
1451: if ($docroot =~ m|public_html/(.+)$|) {
1452: $resdir = $1;
1453: }
1454: my $id; # the current question ID
1455: my $answer_id; # the current answer ID
1456: my %toptag = ( pool => 'POOL',
1457: quiz => 'ASSESSMENT',
1458: survey => 'ASSESSMENT'
1459: );
1460:
1461: my $p = HTML::Parser->new
1462: (
1463: xml_mode => 1,
1464: start_h =>
1465: [sub {
1466: my ($tagname, $attr) = @_;
1467: push @state, $tagname;
1468: my $depth = 0;
1469: my @seq = ();
1470: my $class;
1471: my $state_str = join(" ",@state);
1472: if ($container eq "pool") {
1473: if ("@state" eq "POOL TITLE") {
1474: $$settings{title} = $attr->{value};
1475: }
1476: } else {
1477: if ("@state" eq "ASSESSMENT TITLE") {
1478: $$settings{title} = $attr->{value};
1479: } elsif ("@state" eq "ASSESSMENT FLAG" ) {
1480: $$settings{isnewline} = $attr->{value};
1481: } elsif ("@state" eq "ASSESSMENT FLAGS ISAVAILABLE") {
1482: $$settings{isavailable} = $attr->{value};
1483: } elsif ("@state" eq "ASSESSMENT FLAGS ISANONYMOUS" ) {
1484: $$settings{isanonymous} = $attr->{id};
1485: } elsif ("@state" eq "ASSESSMENT FLAGS GIVE FEEDBACK" ) {
1486: $$settings{feedback} = $attr->{id};
1487: } elsif ("@state" eq "ASSESSMENT FLAGS SHOWCORRECT" ) {
1488: $$settings{showcorrect} = $attr->{id};
1489: } elsif ("@state" eq "ASSESSMENT FLAGS SHOWRESULTS" ) {
1490: $$settings{showresults} = $attr->{id};
1491: } elsif ("@state" eq "ASSESSMENT FLAGS ALLOWMULTIPLE" ) {
1492: $$settings{allowmultiple} = $attr->{id};
1493: } elsif ("@state" eq "ASSESSMENT ASSESSMENTTYPE" ) {
1494: $$settings{type} = $attr->{id};
1495: }
1496: }
1497: if ("@state" eq "$toptag{$container} QUESTIONLIST QUESTION") {
1498: $id = $attr->{id};
1499: unless ($container eq 'pool') {
1500: push @allids, $id;
1501: }
1502: %{$$settings{$id}} = ();
1503: @{$allanswers{$id}} = ();
1504: $$settings{$id}{class} = $attr->{class};
1505: unless ($container eq "pool") {
1506: $$settings{$id}{points} = $attr->{points};
1507: }
1508: @{$$settings{$id}{correctanswer}} = ();
1509: } elsif ( ($state[0] eq $toptag{$container}) && ($state[-1] =~ m/^QUESTION_(\w+)$/) ) {
1510: $id = $attr->{id};
1511: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "FLAGS") ) {
1512: if ($state[4] eq "ISHTML") {
1513: $$settings{$id}{html} = $attr->{value};
1514: } elsif ($state[4] eq "ISNEWLINELITERAL") {
1515: $$settings{$id}{newline} = $attr->{value};
1516: }
1517: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "IMAGE") ) {
1518: $$settings{$id}{image} = $attr->{value};
1519: $$settings{$id}{style} = $attr->{style};
1520: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "URL") ) {
1521: $$settings{$id}{url} = $attr->{value};
1522: $$settings{$id}{name} = $attr->{name};
1523: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[-1] eq "ANSWER") ) {
1524: $answer_id = $attr->{id};
1525: push @{$allanswers{$id}},$answer_id;
1526: %{$$settings{$id}{$answer_id}} = ();
1527: $$settings{$id}{$answer_id}{position} = $attr->{position};
1528: if ($$settings{$id}{class} eq 'QUESTION_MATCH') {
1529: $$settings{$id}{$answer_id}{placement} = $attr->{placement};
1530: $$settings{$id}{$answer_id}{type} = 'answer';
1531: }
1532: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[-1] eq "CHOICE") ) {
1533: $answer_id = $attr->{id};
1534: push @{$allchoices{$id}},$answer_id;
1535: %{$$settings{$id}{$answer_id}} = ();
1536: $$settings{$id}{$answer_id}{position} = $attr->{position};
1537: $$settings{$id}{$answer_id}{placement} = $attr->{placement};
1538: $$settings{$id}{$answer_id}{type} = 'choice';
1539: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "ANSWER") ) {
1540: if ($state[3] eq "IMAGE") {
1541: $$settings{$id}{$answer_id}{image} = $attr->{value};
1542: $$settings{$id}{$answer_id}{style} = $attr->{style};
1543: } elsif ($state[3] eq "URL") {
1544: $$settings{$id}{$answer_id}{url} = $attr->{value};
1545: }
1546: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "CHOICE") ) {
1547: if ($state[3] eq "IMAGE") {
1548: $$settings{$id}{$answer_id}{image} = $attr->{value};
1549: $$settings{$id}{$answer_id}{style} = $attr->{style};
1550: } elsif ($state[3] eq "URL") {
1551: $$settings{$id}{$answer_id}{url} = $attr->{value};
1552: }
1553: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[3] eq "CORRECTANSWER") ) {
1554: my $corr_answer = $attr->{answer_id};
1555: push @{$$settings{$id}{correctanswer}}, $corr_answer;
1556: my $type = $1;
1557: if ($type eq 'TRUEFALSE') {
1558: $$settings{$id}{$corr_answer}{answer_position} = $attr->{position};
1559: } elsif ($type eq 'ORDER') {
1560: $$settings{$id}{$corr_answer}{order} = $attr->{order};
1561: } elsif ($type eq 'MATCH') {
1562: $$settings{$id}{$corr_answer}{choice_id} = $attr->{choice_id};
1563: }
1564: }
1565: }, "tagname, attr"],
1566: text_h =>
1567: [sub {
1568: my ($text) = @_;
1569: unless ($container eq "pool") {
1570: if ("@state" eq "ASSESSMENT DESCRIPTION TEXT") {
1571: $$settings{description} = $text;
1572: } elsif ("@state" eq "ASSESSMENT INSTRUCTIONS ") {
1573: $$settings{instructions}{text} = $text;
1574: }
1575: }
1576: if ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "TEXT") ) {
1577: $$settings{$id}{text} = $text;
1578: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "ANSWER") && ($state[3] eq "TEXT") ) {
1579: $$settings{$id}{$answer_id}{text} = $text;
1580: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "CHOICE") && ($state[3] eq "TEXT") ) {
1581: $$settings{$id}{$answer_id}{text} = $text;
1582: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[3] eq "FEEDBACK_WHEN_CORRECT") ) {
1583: $$settings{$id}{feedback_corr} = $text;
1584: } elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "GRADABLE") && ($state[3] eq "FEEDBACK_WHEN_INCORRECT") ) {
1585: $$settings{$id}{feedback_incorr} = $text;
1586: }
1587: }, "dtext"],
1588: end_h =>
1589: [sub {
1590: my ($tagname) = @_;
1591: pop @state;
1592: }, "tagname"],
1593: );
1594: $p->unbroken_text(1);
1595: $p->parse_file($xmlfile);
1596: $p->eof;
1597:
1598: my $dirtitle = $$settings{'title'};
1599: $dirtitle =~ s/\W//g;
1600: $dirtitle .= '_'.$res;
1601: if (!-e "$destdir/problems/$dirtitle") {
1602: mkdir("$destdir/problems/$dirtitle",0755);
1603: }
1604: my $newdir = "$destdir/problems/$dirtitle";
1605: my $pagedir = "$destdir/pages";
1606: my $curr_id = 0;
1607: my $next_id = 1;
1608: unless ($container eq 'pool') {
1609: open(PAGEFILE,">$pagedir/$res.page");
1610: print PAGEFILE qq|<map>
1611: |;
1612: $$total{page} ++;
1613: print PAGEFILE qq|<resource id="1" src="/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[0].problem" type="start"></resource>|;
1614: if (@allids == 1) {
1615: print PAGEFILE qq|
1616: <link from="1" to="2" index="1"></link>
1617: <resource id="2" src="" type="finish">\n|;
1618: } else {
1619: for (my $j=1; $j<@allids; $j++) {
1620: $curr_id = $j;
1621: $next_id = $curr_id + 1;
1622: print PAGEFILE qq|
1623: <link from="$curr_id" to="$next_id" index="$curr_id"></link>
1624: <resource id="$next_id" src="/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[$j].problem"|;
1625: if ($next_id == @allids) {
1626: print PAGEFILE qq| type="finish"></resource>\n|;
1627: } else {
1628: print PAGEFILE qq|></resource>|;
1629: }
1630: }
1631: }
1632: print PAGEFILE qq|</map>|;
1633: close(PAGEFILE);
1634: }
1635: foreach my $id (@allids) {
1636: my $output = qq|<problem>
1637: |;
1.3 raeburn 1638: $$total{prob} ++;
1.2 raeburn 1639: if ($$settings{$id}{class} eq "QUESTION_ESSAY") {
1640: $output .= qq|<startouttext />$$settings{$id}{text}<endouttext />
1641: <essayresponse>
1642: <textfield></textfield>
1643: </essayresponse>
1644: <postanswerdate>
1645: $$settings{$id}{feedbackcorr}
1646: </postanswerdate>
1647: |;
1648: } else {
1649: $output .= qq|<startouttext />$$settings{$id}{text}\n|;
1650: if ( defined($$settings{$id}{image}) ) {
1651: if ( $$settings{$id}{style} eq 'embed' ) {
1652: $output .= qq|<br /><img src="$dirname/resfiles/$res/$$settings{$id}{image}" /><br />|;
1653: } else {
1654: $output .= qq|<br /><a href="$dirname/resfiles/$res/$$settings{$id}{image}">Link to file</a><br />|;
1655: }
1656: }
1657: if ( defined($$settings{$id}{url}) ) {
1658: $output .= qq|<br /><a href="$$settings{$id}{url}">$$settings{$id}{name}</a><br />|;
1659: }
1660: $output .= qq|
1661: <endouttext />|;
1662: if ($$settings{$id}{class} eq 'QUESTION_MULTIPLECHOICE') {
1663: my $numfoils = @{$allanswers{$id}};
1664: $output .= qq|
1665: <radiobuttonresponse max="$numfoils" randomize="yes">
1666: <foilgroup>
1667: |;
1668: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1669: $output .= " <foil name=\"foil".$k."\" value=\"";
1670: if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1671: $output .= "true\" location=\"";
1672: } else {
1673: $output .= "false\" location=\"";
1674: }
1675: if (lc ($allanswers{$id}[$k]) =~ m/^\s?([Aa]ll)|([Nn]one)\sof\sthe\sabove\.?/) {
1676: $output .= "bottom\"";
1677: } else {
1678: $output .= "random\"";
1679: }
1680: $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text};
1681: if ( defined($$settings{$id}{$allanswers{$id}[$k]}{image}) ) {
1682: if ( $$settings{$id}{$allanswers{$id}[$k]}{style} eq 'embed' ) {
1683: $output .= qq|<br /><img src="$dirname/resfiles/$res/$$settings{$id}{$allanswers{$id}[$k]}{image}" /><br />|;
1684: } else {
1685: $output .= qq|<br /><a href="$dirname/resfiles/$res/$$settings{$id}{$allanswers{$id}[$k]}{image}" />Link to file</a><br/>|;
1686: }
1687: }
1688: $output .= qq|<endouttext /></foil>\n|;
1689: }
1690: chomp($output);
1691: $output .= qq|
1692: </foilgroup>
1693: </radiobuttonresponse>
1694: |;
1695: } elsif ($$settings{$id}{class} eq 'QUESTION_TRUEFALSE') {
1696: my $numfoils = @{$allanswers{$id}};
1697: $output .= qq|
1698: <radiobuttonresponse max="$numfoils" randomize="yes">
1699: <foilgroup>
1700: |;
1701: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1702: $output .= " <foil name=\"foil".$k."\" value=\"";
1703: if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1704: $output .= "true\" location=\"random\"";
1705: } else {
1706: $output .= "false\" location=\"random\"";
1707: }
1708: $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
1709: }
1710: chomp($output);
1711: $output .= qq|
1712: </foilgroup>
1713: </radiobuttonresponse>
1714: |;
1715: } elsif ($$settings{$id}{class} eq 'QUESTION_MULTIPLEANSWER') {
1716: my $numfoils = @{$allanswers{$id}};
1717: $output .= qq|
1718: <optionresponse max="$numfoils" randomize="yes">
1719: <foilgroup options="('True','False')">
1720: |;
1721: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1722: $output .= " <foil name=\"foil".$k."\" value=\"";
1723: if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
1724: $output .= "True\"";
1725: } else {
1726: $output .= "False\"";
1727: }
1728: $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
1729: }
1730: chomp($output);
1731: $output .= qq|
1732: </foilgroup>
1733: </optionresponse>
1734: |;
1735: } elsif ($$settings{$id}{class} eq 'QUESTION_ORDER') {
1736: my $numfoils = @{$allanswers{$id}};
1737: $output .= qq|
1738: <rankresponse max="$numfoils" randomize="yes">
1739: <foilgroup>
1740: |;
1741: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1742: $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$allanswers{$id}[$k]}{order}."\"><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
1743: }
1744: chomp($output);
1745: $output .= qq|
1746: </foilgroup>
1747: </rankresponse>
1748: |;
1749: } elsif ($$settings{$id}{class} eq 'QUESTION_FILLINBLANK') {
1750: my $numerical = 1;
1751: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1752: if ($$settings{$id}{$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) {
1753: $numerical = 0;
1754: }
1755: }
1756: if ($numerical) {
1757: my $numans;
1758: my $tol;
1759: if (@{$allanswers{$id}} == 1) {
1760: $tol = 5;
1761: $numans = $$settings{$id}{$allanswers{$id}[0]}{text};
1762: } else {
1763: my $min = $$settings{$id}{$allanswers{$id}[0]}{text};
1764: my $max = $$settings{$id}{$allanswers{$id}[0]}{text};
1765: for (my $k=1; $k<@{$allanswers{$id}}; $k++) {
1766: if ($$settings{$id}{$allanswers{$id}[$k]}{text} <= $min) {
1767: $min = $$settings{$id}{$allanswers{$id}[$k]}{text};
1768: }
1769: if ($$settings{$id}{$allanswers{$id}[$k]}{text} >= $max) {
1770: $max = $$settings{$id}{$allanswers{$id}[$k]}{text};
1771: }
1772: }
1773: $numans = ($max + $min)/2;
1774: $tol = 100*($max - $min)/($numans*2);
1775: }
1776: $output .= qq|
1777: <numericalresponse answer="$numans">
1778: <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
1779: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures"
1780: />
1781: <textline />
1782: </numericalresponse>
1783: |;
1784: } else {
1785: if (@{$allanswers{$id}} == 1) {
1786: $output .= qq|
1787: <stringresponse answer="$$settings{$id}{$allanswers{$id}[0]}{text}" type="ci">
1788: <textline>
1789: </textline>
1790: </stringresponse>
1791: |;
1792: } else {
1793: my @answertext = ();
1794: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1795: $$settings{$id}{$allanswers{$id}[$k]}{text} =~ s/\|/\|/g;
1796: push @answertext, $$settings{$id}{$allanswers{$id}[$k]}{text};
1797: }
1798: my $regexpans = join('|',@answertext);
1799: $regexpans = '/^('.$regexpans.')\b/';
1800: $output .= qq|
1801: <stringresponse answer="$regexpans" type="re">
1802: <textline>
1803: </textline>
1804: </stringresponse>
1805: |;
1806: }
1807: }
1808: } elsif ($$settings{$id}{class} eq "QUESTION_MATCH") {
1809: $output .= qq|
1810: <matchresponse max="10" randomize="yes">
1811: <foilgroup>
1812: <itemgroup>
1813: |;
1814: for (my $k=0; $k<@{$allchoices{$id}}; $k++) {
1815: $output .= qq|
1816: <item name="$allchoices{$id}[$k]">
1817: <startouttext />$$settings{$id}{$allchoices{$id}[$k]}{text}<endouttext />
1818: </item>
1819: |;
1820: }
1821: $output .= qq|
1822: </itemgroup>
1823: |;
1824: for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
1825: $output .= qq|
1826: <foil location="random" value="$$settings{$id}{$allanswers{$id}[$k]}{choice_id}" name="$allanswers{$id}[$k]">
1827: <startouttext />$$settings{$id}{$allanswers{$id}[$k]}{text}<endouttext />
1828: </foil>
1829: |;
1830: }
1831: $output .= qq|
1832: </foilgroup>
1833: </matchresponse>
1834: |;
1835: }
1836: }
1837: $output .= qq|</problem>
1838: |;
1839: open(PROB,">$newdir/$id.problem");
1840: print PROB $output;
1841: close PROB;
1842: }
1843: }
1844:
1845: # ---------------------------------------------------------------- Process Blackboard Announcements
1846: sub process_announce {
1.3 raeburn 1847: my ($res,$docroot,$destdir,$settings,$globalresref,$seqstem,$resrcfiles) = @_;
1.2 raeburn 1848: my $xmlfile = $docroot.'/'.$res.".dat";
1849: my @state = ();
1850: my @assess = ();
1851: my $id;
1852: my $p = HTML::Parser->new
1853: (
1854: xml_mode => 1,
1855: start_h =>
1856: [sub {
1857: my ($tagname, $attr) = @_;
1858: push @state, $tagname;
1859: if ("@state" eq "ANNOUNCEMENT TITLE") {
1860: $$settings{title} = $attr->{value};
1861: $$settings{startassessment} = ();
1.7 raeburn 1862: } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISHTML") {
1.2 raeburn 1863: $$settings{ishtml} = $attr->{value};
1864: } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISNEWLINELITERAL" ) {
1865: $$settings{isnewline} = $attr->{value};
1866: } elsif ("@state" eq "ANNOUNCEMENT ISPERMANENT" ) {
1867: $$settings{ispermanent} = $attr->{value};
1868: } elsif ("@state" eq "ANNOUNCEMENT DATES UPDATED") {
1869: $$settings{dates} = $attr->{value};
1870: } elsif ("@state" eq "ANNOUNCEMENT FILES STARTASSESSMENT" ) {
1871: $id = $attr->{id};
1872: %{$$settings{startassessment}{$id}} = ();
1873: push @assess,$id;
1874: } elsif ("@state" eq "ANNOUNCEMENT FILES STARTASSESSMENT ATTRIB" ) {
1875: my $key = $attr->{key};
1876: $$settings{startassessment}{$id}{$key} = $attr->{value};
1877: }
1878: }, "tagname, attr"],
1879: text_h =>
1880: [sub {
1881: my ($text) = @_;
1882: if ("@state" eq "ANNOUNCEMENT DESCRIPTION TEXT") {
1883: $$settings{text} = $text;
1884: }
1885: }, "dtext"],
1886: end_h =>
1887: [sub {
1888: my ($tagname) = @_;
1889: pop @state;
1890: }, "tagname"],
1891: );
1892: $p->unbroken_text(1);
1893: $p->parse_file($xmlfile);
1894: $p->eof;
1895:
1896: if (defined($$settings{text})) {
1897: if ($$settings{ishtml} eq "false") {
1898: if ($$settings{isnewline} eq "true") {
1899: $$settings{text} =~ s#\n#<br/>#g;
1900: }
1901: } else {
1902: $$settings{text} = &HTML::Entities::decode($$settings{text});
1903: }
1904: }
1905:
1906: if (@assess > 0) {
1907: foreach my $id (@assess) {
1.3 raeburn 1908: $$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 1909: }
1910: }
1911:
1912: open(FILE,">$destdir/resfiles/$res.html");
1913: push @{$resrcfiles}, "$res.html";
1914: print FILE qq|<html>
1915: <head>
1916: <title>$$settings{title}</title>
1917: </head>
1918: <body bgcolor='#ffffff'>
1919: <table>
1920: <tr>
1.3 raeburn 1921: <td bgcolor='#CCCCFF'>$$settings{title} - announcement date: $$settings{dates}</td>
1.2 raeburn 1922: </tr>
1923: </table>
1924: <br/>
1925: $$settings{text}
1926: |;
1927: print FILE qq|
1928: </body>
1929: </html>|;
1930: close(FILE);
1931: }
1932:
1933: # ---------------------------------------------------------------- Process Blackboard Content
1934: sub process_content {
1.7 raeburn 1935: my ($res,$context,$docroot,$destdir,$settings,$dom,$user,$resrcfiles) = @_;
1.2 raeburn 1936: my $xmlfile = $docroot.'/'.$res.".dat";
1937: my $destresdir = $destdir;
1.7 raeburn 1938: if ($context eq 'CSTR') {
1939: $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
1940: } elsif ($context eq 'DOCS') {
1941: $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
1942: }
1.2 raeburn 1943: my $filecount = 0;
1944: my @allrelfiles = ();
1945: my @state;
1946: @{$$settings{files}} = ();
1947: my $p = HTML::Parser->new
1948: (
1949: xml_mode => 1,
1950: start_h =>
1951: [sub {
1952: my ($tagname, $attr) = @_;
1953: push @state, $tagname;
1.7 raeburn 1954: if ("@state" eq "CONTENT MAINDATA") {
1.2 raeburn 1955: %{$$settings{maindata}} = ();
1.7 raeburn 1956: } elsif ("@state" eq "CONTENT MAINDATA TEXTCOLOR") {
1.2 raeburn 1957: $$settings{maindata}{color} = $attr->{value};
1.7 raeburn 1958: } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISHTML") {
1.2 raeburn 1959: $$settings{maindata}{ishtml} = $attr->{value};
1.7 raeburn 1960: } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISNEWLINELITERAL") {
1.2 raeburn 1961: $$settings{maindata}{isnewline} = $attr->{value};
1962: } elsif ("@state" eq "CONTENT FLAGS ISAVAILABLE" ) {
1963: $$settings{isavailable} = $attr->{value};
1964: } elsif ("@state" eq "CONTENT FLAGS ISFOLDER" ) {
1965: $$settings{isfolder} = $attr->{value};
1966: } elsif ("@state" eq "CONTENT FLAGS LAUNCHINNEWWINDOW" ) {
1967: $$settings{newwindow} = $attr->{value};
1968: } elsif ("@state" eq "CONTENT FILES FILEREF") {
1969: %{$$settings{files}[$filecount]} = ();
1970: %{$$settings{files}[$filecount]{registry}} = ();
1971: } elsif ("@state" eq "CONTENT FILES FILEREF RELFILE" ) {
1972: $$settings{files}[$filecount]{'relfile'} = $attr->{value};
1973: push @allrelfiles, $attr->{value};
1974: } elsif ("@state" eq "CONTENT FILES FILEREF MIMETYPE") {
1975: $$settings{files}[$filecount]{mimetype} = $attr->{value};
1976: } elsif ("@state" eq "CONTENT FILES FILEREF CONTENTTYPE") {
1977: $$settings{files}[$filecount]{contenttype} = $attr->{value};
1978: } elsif ("@state" eq "CONTENT FILES FILEREF FILEACTION") {
1979: $$settings{files}[$filecount]{fileaction} = $attr->{value};
1980: } elsif ("@state" eq "CONTENT FILES FILEREF PACKAGEPARENT") {
1981: $$settings{files}[$filecount]{packageparent} = $attr->{value};
1982: } elsif ("@state" eq "CONTENT FILES FILEREF LINKNAME") {
1983: $$settings{files}[$filecount]{linkname} = $attr->{value};
1984: } elsif ("@state" eq "CONTENT FILES FILEREF REGISTRY REGISTRYENTRY") {
1985: my $key = $attr->{key};
1986: $$settings{files}[$filecount]{registry}{$key} = $attr->{value};
1987: }
1988: }, "tagname, attr"],
1989: text_h =>
1990: [sub {
1991: my ($text) = @_;
1992: if ("@state" eq "CONTENT TITLE") {
1993: $$settings{title} = $text;
1994: } elsif ("@state" eq "CONTENT MAINDATA TEXT") {
1995: $$settings{maindata}{text} = $text;
1996: } elsif ("@state" eq "CONTENT FILES FILEREF REFTEXT") {
1997: $$settings{files}[$filecount]{reftext} = $text;
1998: }
1999: }, "dtext"],
2000: end_h =>
2001: [sub {
2002: my ($tagname) = @_;
2003: if ("@state" eq "CONTENT FILES FILEREF") {
2004: $filecount ++;
2005: }
2006: pop @state;
2007: }, "tagname"],
2008: );
2009: $p->unbroken_text(1);
2010: $p->parse_file($xmlfile);
2011: $p->eof;
2012: my $linktag = '';
2013: my $fontcol = '';
2014: if (@{$$settings{files}} > 0) {
2015: for (my $filecount=0; $filecount<@{$$settings{files}}; $filecount++) {
2016: if ($$settings{files}[$filecount]{'fileaction'} eq 'embed') {
2017: if ( $$settings{files}[$filecount]{reftext} =~ m#<\!\-\-\s_(\d+)\\_\s\-\-\>#) {
2018: my $newtag = qq|<img src="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"/>|;
2019: $$settings{maindata}{text} =~ s#<\!\-\-\s_/($1)\\_\s\-\-\>#$newtag#;
2020: } elsif ( $$settings{files}[$filecount]{reftext} =~m#^_/(\d+)\\_$# ) {
2021: my $reftag = $1;
2022: my $newtag;
2023: if ($$settings{files}[$filecount]{mimetype} =~ m/^image/) {
2024: $newtag = qq|<img src="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"|;
2025: if ( defined($$settings{files}[$filecount]{registry}{alttext}) ) {
2026: $newtag .= qq| alt="$$settings{files}[$filecount]{registry}{alttext}"|;
2027: }
2028: if ( defined($$settings{files}[$filecount]{registry}{alignment}) )
2029: {
2030: $newtag .= qq| align="$$settings{files}[$filecount]{registry}{alignment}"|;
1.1 raeburn 2031: }
1.2 raeburn 2032: if ( defined($$settings{files}[$filecount]{registry}{border}) ) {
2033: $newtag .= qq| border="$$settings{files}[$filecount]{registry}{border}"|;
2034: }
2035: $newtag .= " />";
2036: my $reftext = $$settings{files}[$filecount]{reftext};
2037: my $fname = $$settings{files}[$filecount]{'relfile'};
2038: $$settings{maindata}{text} =~ s/<!\-\-\sCOMMENT\sBLOCK\sFOR\sEMBEDDED\sFILE:\s$fname[\s\n]+DO\sNOT\sEDIT\sTHIS\sCOMMENT\sBLOCK[\s\n]+//;
2039: # $$settings{maindata}{text} =~ s/DO\sNOT\sEDIT\sTHIS\sCOMMENT\sBLOCK[\s\n]+//;
2040: $$settings{maindata}{text} =~ s/Move\swhole\scomment\sto\schange\sfile\splacement\swithin\spage\.[\s\n]+//;
2041: $$settings{maindata}{text} =~ s/_\/$reftag\\_/$newtag/;
2042: $$settings{maindata}{text} =~ s/END\sOF\sBLOCK\sON\sNEXT\sLINE[\s\n]+//;
2043: $$settings{maindata}{text} =~ s/\-\->//;
2044: # $$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/;
2045: # print STDERR $$settings{maindata}{text};
2046: }
2047: } else {
2048: my $filename=$$settings{files}[$filecount]{'relfile'};
2049: # print "File is $filename\n";
2050: my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}";
2051: # print "New filename is $newfilename\n";
2052: $$settings{maindata}{text} =~ s#(src|SRC|value)="$filename"#$1="$newfilename"#g;
2053: }
2054: } elsif ($$settings{files}[$filecount]{fileaction} eq 'link') {
2055: unless (($$settings{files}[$filecount]{packageparent} ne '') && (grep/^$$settings{files}[$filecount]{packageparent}$/,@{$$settings{files}}) ) {
2056: $linktag .= qq|<a href="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"|;
2057: if ($$settings{newwindow} eq "true") {
2058: $linktag .= qq| target="$res$filecount"|;
1.1 raeburn 2059: }
1.2 raeburn 2060: foreach my $entry (keys %{$$settings{files}[$filecount]{registry}}) {
2061: $linktag .= qq| $entry="$$settings{files}[$filecount]{registry}{$entry}"|;
1.1 raeburn 2062: }
1.2 raeburn 2063: $linktag .= qq|>$$settings{files}[$filecount]{linkname}</a><br/>\n|;
1.1 raeburn 2064: }
1.2 raeburn 2065: } elsif ($$settings{files}[$filecount]{fileaction} eq 'package') {
2066: # print "Found a package\n";
1.1 raeburn 2067: }
1.2 raeburn 2068: }
2069: }
2070: if (defined($$settings{maindata}{textcolor})) {
2071: $fontcol = qq|<font color="$$settings{maindata}{textcolor}">|;
2072: }
2073: if (defined($$settings{maindata}{text})) {
2074: if ($$settings{maindata}{ishtml} eq "false") {
2075: if ($$settings{maindata}{isnewline} eq "true") {
2076: $$settings{maindata}{text} =~ s#\n#<br/>#g;
2077: }
2078: } else {
2079: $$settings{maindata}{text} = &HTML::Entities::decode($$settings{maindata}{text});
2080: }
2081: }
2082:
2083: open(FILE,">$destdir/resfiles/$res.html");
2084: push @{$resrcfiles}, "$res.html";
2085: print FILE qq|<html>
2086: <head>
2087: <title>$$settings{title}</title>
2088: </head>
2089: <body bgcolor='#ffffff'>
2090: $fontcol
2091: |;
2092: unless ($$settings{title} eq '') {
2093: print FILE qq|$$settings{title}<br/><br/>\n|;
2094: }
2095: print FILE qq|
2096: $$settings{maindata}{text}
2097: $linktag|;
2098: if (defined($$settings{maindata}{textcolor})) {
2099: print FILE qq|</font>|;
2100: }
2101: print FILE qq|
2102: </body>
2103: </html>|;
2104: close(FILE);
2105: }
2106:
2107:
2108: sub process_angelboards {
2109: my ($context,$destdir,$boards,$timestamp,$crs,$cdom,$uname,$db_handling,$messages,$items,$resources,$hrefs,$tempdir,$longcrs) = @_;
2110: for (my $i=0; $i<@{$boards}; $i++) {
2111: my %msgidx = ();
2112: my $forumtext = '';
2113: my $boardname = 'bulletinpage_'.$$timestamp[$i];
2114: my $forumfile = $tempdir.'/_assoc/'.$$boards[$i].'/pg'.$$boards[$i].'.htm';
2115: my @state = ();
2116: my $p = HTML::Parser->new
2117: (
2118: xml_mode => 1,
2119: start_h =>
2120: [sub {
2121: my ($tagname, $attr) = @_;
2122: push @state, $tagname;
2123: }, "tagname, attr"],
2124: text_h =>
2125: [sub {
2126: my ($text) = @_;
2127: if ("@state" eq "html body div div") {
2128: $forumtext = $text;
2129: }
2130: }, "dtext"],
2131: end_h =>
2132: [sub {
2133: my ($tagname) = @_;
2134: pop @state;
2135: }, "tagname"],
2136: );
2137: $p->parse_file($forumfile);
2138: $p->eof;
2139:
2140: my %boardinfo = (
2141: 'aaa_title' => $$items{$$resources{$$boards[$i]}{revitm}}{title},
2142: 'bbb_content' => $forumtext,
2143: 'ccc_webreferences' => '',
2144: 'uploaded.lastmodified' => time,
2145: );
2146: my $msgcount = 0;
2147:
2148: my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$cdom,$crs);
2149: # print STDERR "putresult is $putresult for $boardname $cdom $crs\n";
2150: if ($db_handling eq 'importall') {
2151: foreach my $msg_id (@{$$messages{$$boards[$i]}}) {
2152: $msgcount ++;
2153: $msgidx{$msg_id} = $msgcount;
2154: my %contrib = (
2155: 'sendername' => 'NoName',
2156: 'senderdomain' => $cdom,
2157: 'screenname' => '',
2158: 'message' => $$items{$$resources{$msg_id}{revitm}}{title}
2159: );
2160: unless ( $$items{$$resources{$msg_id}{revitm}}{parentseq} eq $$resources{$$boards[$i]}{revitm} ) {
2161: unless ( $msgidx{$$items{$$items{$$resources{$msg_id}{revitm}}{parentseq}}{resnum}} eq ''){
2162: $contrib{replyto} = $msgidx{$$items{$$items{$$resources{$msg_id}{revitm}}{parentseq}}{resnum}};
1.1 raeburn 2163: }
1.2 raeburn 2164: }
2165: if ( @{$$hrefs{$msg_id}} > 1 ) {
2166: my $newurl = '';
2167: foreach my $file (@{$$hrefs{$msg_id}}) {
2168: unless ($file eq 'pg'.$msg_id.'.htm') {
2169: $newurl = $msg_id.$file;
2170: unless ($longcrs eq '') {
2171: if ($context eq 'CSTR') {
2172: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles") {
2173: mkdir("/home/httpd/lonUsers/$cdom/$longcrs/userfiles",0755);
2174: }
2175: if (!-e "/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl") {
2176: rename("$destdir/resfiles/$msg_id/$file","/home/httpd/lonUsers/$cdom/$longcrs/userfiles/$newurl");
2177: }
2178: }
2179: $contrib{attachmenturl} = '/uploaded/'.$cdom.'/'.$crs.'/'.$file;
2180: }
1.1 raeburn 2181: }
2182: }
2183: }
1.2 raeburn 2184: my $xmlfile = $tempdir.'/_assoc/'.$msg_id.'/'.$$resources{$msg_id}{file};
2185: &angel_message($msg_id,\%contrib,$xmlfile);
2186: unless ($$resources{$msg_id}{file} eq '') {
2187: unlink($xmlfile);
2188: }
2189: my $symb = 'bulletin___'.$$timestamp[$i].'___adm/wrapper/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$i].'/bulletinboard';
2190: my $postresult = &addposting($symb,\%contrib,$cdom,$crs);
2191: }
2192: }
2193: }
2194: }
2195:
2196: # ---------------------------------------------------------------- Process ANGEL message board messages
2197: sub angel_message {
2198: my ($msg_id,$contrib,$xmlfile) = @_;
2199: my @state = ();
2200: my $p = HTML::Parser->new
2201: (
2202: xml_mode => 1,
2203: start_h =>
2204: [sub {
2205: my ($tagname, $attr) = @_;
2206: push @state, $tagname;
2207: }, "tagname, attr"],
2208: text_h =>
2209: [sub {
2210: my ($text) = @_;
2211: if ("@state" eq "html body table tr td div small span") {
2212: $$contrib{'plainname'} = $text;
2213: } elsif ("@state" eq "html body div div") {
2214: $$contrib{'message'} .= '<br /><br />'.$text;
2215: }
2216: }, "dtext"],
2217: end_h =>
2218: [sub {
2219: my ($tagname) = @_;
2220: pop @state;
2221: }, "tagname"],
2222: );
2223: $p->parse_file($xmlfile);
2224: $p->eof;
2225: }
2226:
2227: # ---------------------------------------------------------------- ANGEL content
2228: sub angel_content {
2229: my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
2230: my $xmlfile = $docroot.'/_assoc/'.$res.'/pg'.$res.'.htm';
2231: my $filecount = 0;
2232: my $firstline;
2233: my $lastline;
2234: my @buffer = ();
2235: my @state;
2236: @{$$settings{links}} = ();
2237: my $p = HTML::Parser->new
2238: (
2239: xml_mode => 1,
2240: start_h =>
2241: [sub {
2242: my ($tagname, $attr) = @_;
2243: push @state, $tagname;
2244: }, "tagname, attr"],
2245: text_h =>
2246: [sub {
2247: my ($text) = @_;
2248: if ("@state" eq "html body table tr td div small span") {
2249: $$settings{'subtitle'} = $text;
2250: } elsif ("@state" eq "html body div div") {
2251: $$settings{'text'} = $text;
2252: } elsif ("@state" eq "html body div div a") {
2253: push @{$$settings{'links'}}, $text;
2254: }
2255: }, "dtext"],
2256: end_h =>
2257: [sub {
2258: my ($tagname) = @_;
2259: pop @state;
2260: }, "tagname"],
2261: );
2262: $p->parse_file($xmlfile);
2263: $p->eof;
2264: if ($type eq "PAGE") {
2265: open(FILE,"<$xmlfile");
2266: @buffer = <FILE>;
2267: close(FILE);
2268: chomp(@buffer);
2269: $firstline = -1;
2270: $lastline = 0;
2271: for (my $i=0; $i<@buffer; $i++) {
2272: if (($firstline == -1) && ($buffer[$i] =~ m/<div\sclass="normalDiv"><div\sclass="normalSpan">/)) {
2273: $firstline = $i;
2274: $buffer[$i] = substr($buffer[$i],index($buffer[$i],'"normalSpan"')+13);
2275: }
2276: if (($firstline > -1) && ($buffer[$i] =~ m-<p></p></div></div>-)) {
2277: $buffer[$i] = substr($buffer[$i],0,index($buffer[$i],'<p></p></div></div>'));
2278: $lastline = $i;
1.1 raeburn 2279: }
2280: }
2281: }
1.2 raeburn 2282: open(FILE,">$destdir/resfiles/$res.html");
2283: push @{$resrcfiles}, "$res.html";
2284: print FILE qq|<html>
2285: <head>
2286: <title>$title</title>
2287: </head>
2288: <body bgcolor='#ffffff'>
2289: |;
2290: unless ($title eq '') {
2291: print FILE qq|<b>$title</b><br/>\n|;
2292: }
2293: unless ($$settings{subtitle} eq '') {
2294: print FILE qq|$$settings{subtitle}<br/>\n|;
2295: }
2296: print FILE "<br/>\n";
2297: if ($type eq "LINK") {
2298: foreach my $link (@{$$settings{links}}) {
2299: print FILE qq|<a href="$link">$link</a><br/>\n|;
2300: }
2301: } elsif ($type eq "PAGE") {
2302: if ($firstline > -1) {
2303: for (my $i=$firstline; $i<=$lastline; $i++) {
2304: print FILE "$buffer[$i]\n";
2305: }
2306: }
2307: }
2308: print FILE qq|
2309: </body>
2310: </html>|;
2311: close(FILE);
1.1 raeburn 2312: }
2313:
2314: 1;
2315: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>