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