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