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