Parent Directory
|
Revision Log
remove unneccsary shebang lines Arnie
1 2 3 use strict; 4 5 ## $ENV{'PATH'} .= ':/usr/math/bin'; 6 7 my $debug = 0; 8 $debug = 1 if $Global::imageDebugMode; 9 ## if $debug =1, log, etc. files created by 10 ## latex2html are not deleted 11 12 ############################################################## 13 # File: DisplayMacros.pl 14 # This contains the subroutines for creating problem files 15 ############################################################## 16 17 ################################################################ 18 # Copyright @1995-1998 by Michael E. Gage, Arnold K. Pizer and 19 # WeBWorK at the University of Rochester. All rights reserved. 20 ################################################################ 21 22 23 ## To add or delete displayModes edit this file 24 25 sub displaySelectModeLine_string 26 # called from probSet.pl 27 # displays the option line for selecting display modes 28 { 29 my ($displayMode) =@_ ; 30 my $out = "Display Mode: <BR>"; 31 32 # A list of the available modes. 33 my $mode_list = $Global::available_mode_list; ## ref to a list of available modes 34 ## The format is [internal symbol, external name] 35 # A list of the available modes. 36 # Format is [internal symbol, external name, ""], where the third 37 # argument is changed to checked below for the current displayMode 38 # my $mode_list = [ 39 # ['HTML', 'text', ""], 40 # ['HTML_tth', 'formatted-text',""], 41 # ['HTML_dpng' ,'dvipng',""], 42 # ['Latex2HTML', 'typeset',""] 43 # ]; 44 45 # Make the format [internal symbol, external name, ''] 46 # The third argument is changed to checked below for the current displayMode 47 my $j; 48 for $j (0..(scalar(@{$mode_list})-1)) { 49 push @{$mode_list->[$j]},''; 50 } 51 52 if (! defined($displayMode) ) {$displayMode = $Global::htmldisplayModeDefault;} 53 54 55 my $found = 0; 56 # Search through all modes to match for displayMode 57 # If we don't find one, found=0 will trigger warn message below 58 for $j (0..(scalar(@{$mode_list})-1)) { 59 if($mode_list->[$j]->[0] eq $displayMode) { 60 $mode_list->[$j]->[2] = "CHECKED"; 61 $found=1; 62 last; 63 } 64 } 65 66 for $j (@{$mode_list}) { 67 $out .= qq!<INPUT TYPE=RADIO NAME="Mode" VALUE="$j->[0]" $j->[2]>$j->[1]<BR>\n!; 68 } 69 if(! $found) { 70 my $wstr = " Error: displayMacros.pl: sub displaySelectModeLine. Unrecognized mode |$displayMode| . The acceptable modes are: "; 71 for $j (@{$mode_list}) { 72 $wstr .= " $j->[0] "; 73 } 74 warn $wstr; 75 } 76 $out; 77 } 78 79 sub displaySelectModeLine { 80 print displaySelectModeLine_string(@_); 81 } 82 ################################################################################################################## 83 # Does the initial processing of the problem. 84 # Returns an array containing the rendered problem. # 85 ################################################################################################################## 86 87 sub createDisplayedProblem { 88 89 my ($setNumber,$probNum,$psvn,$printlinesref,$rh_flags)= @_; 90 my @printlines; 91 92 93 my $coursel2hDirectory = getCoursel2hDirectory(); 94 unless(-e $coursel2hDirectory ) { 95 &createDirectory($coursel2hDirectory, $Global::l2h_set_directory_permission, 96 $Global::numericalGroupID); 97 } 98 99 unless(-e "${coursel2hDirectory}set$setNumber") { 100 &createDirectory("${coursel2hDirectory}set$setNumber",$Global::l2h_set_directory_permission, 101 $Global::numericalGroupID); 102 } 103 104 105 my $PROBDIR = convertPath("${coursel2hDirectory}set$setNumber/$probNum-$psvn/"); 106 my $TMPPROBDIR = convertPath("${coursel2hDirectory}$probNum-$psvn/"); 107 108 if (! -e $PROBDIR) { # no gifs of equations have been created 109 &l2hcreate($setNumber,$probNum,$psvn,$printlinesref); 110 111 } else { # determine if the gifs are older than the modifications of the source file 112 #&attachProbSetRecord($psvn); 113 my $fileName = &getProblemFileName($probNum,$psvn); 114 $fileName = "${Global::templateDirectory}$fileName"; 115 #print "\n\n The filename is $fileName \n\n"; 116 my @probDirStat = stat $PROBDIR; 117 my @sourceFileStat = stat $fileName; 118 #print "\n\n The source file age is $sourceFileStat[9] \n\n"; 119 #print "\n\n The prob dir age is $probDirStat[9] \n\n"; 120 121 if (($sourceFileStat[9] > $probDirStat[9] ) or 122 $rh_flags->{'refreshCachedImages'}) { 123 ## source file is newer or solutions should be shown recreate the l2h cache 124 rmDirectoryAndFiles($PROBDIR); 125 &l2hcreate($setNumber,$probNum,$psvn,$printlinesref); 126 } 127 128 129 } 130 #the problem has been rendered by Latex2HTML into this file: 131 # open(TEXXX, "${PROBDIR}${psvn}output.html") || die "Can't open ${PROBDIR}${psvn}output.html"; 132 open(TEXXX, "${PROBDIR}${psvn}output.html") or 133 warn "ERROR: $0". 134 "Can't open the HTML file: \n ${PROBDIR}${psvn}output.html\n(allegedly)". 135 "translated by latex2HTML\n at displayMacros.pl, line" . __LINE__ ; 136 137 @printlines = <TEXXX>; 138 push(@printlines, "The file ${PROBDIR}${psvn}output.html was empty") unless @printlines; 139 #print "PRINTLINES",@printlines; 140 close(TEXXX); 141 142 @printlines; 143 } 144 145 146 147 ########################################################################################### 148 # Formats and displays the responses to submitted answers to the problem. Returns a string. # 149 ########################################################################################### 150 151 sub display_answers { # this will be put in displayMacros.pl soon. 152 #my ($displayCorrectAnswersQ,$showPartialCorrectAnswers,$rh_answer_results,$rh_problem_result) = @_; 153 my ($rh_answer_results,$rh_problem_result,$rh_flags) = @_; 154 my $displayCorrectAnswersQ = $rh_flags ->{displayCorrectAnswersQ}; 155 my $showPartialCorrectAnswers = $rh_flags -> {showPartialCorrectAnswers}; 156 my @answer_entry_order = @{$rh_flags -> {ANSWER_ENTRY_ORDER} }; 157 my $ANSWER_PREFIX = $rh_flags -> {ANSWER_PREFIX}; 158 my $allAnswersCorrectQ = 1; 159 my $printedResponse=''; 160 ###### Print appropriate response to submitted answers 161 my ($i,$answerIsCorrectQ, $normalizedSubmittedAnswer,$normalizedCorrectAnswer,$ans_name,$errors); 162 $i=0; 163 $printedResponse .= "\n<table border=0 cellpadding=0 cellspacing=0 bgcolor=\"#cccccc\">\n"; 164 foreach my $key ( @answer_entry_order ) { 165 166 $i++; 167 $answerIsCorrectQ = $rh_answer_results ->{$key} -> {score}; 168 $normalizedSubmittedAnswer = $rh_answer_results ->{$key} -> {student_ans}; 169 $normalizedSubmittedAnswer = '' if ($normalizedSubmittedAnswer =~ /^error:\s+empty/); 170 $normalizedCorrectAnswer = $rh_answer_results ->{$key} -> {original_correct_ans}; 171 172 ## Handle the case where the answer evaluator does not return original_correct_ans 173 if ((!defined $normalizedCorrectAnswer) or (!$normalizedCorrectAnswer =~ /\S/)) { 174 $normalizedCorrectAnswer = $rh_answer_results ->{$key} -> {correct_ans}; 175 } 176 177 $errors = $rh_answer_results ->{$key} -> {ans_message}; 178 $errors = '' if ($errors eq 'empty'); 179 #$ans_name = $rh_answer_results ->{$key} -> {ans_name}; 180 #$ans_name =~ s/$ANSWER_PREFIX//; # this handles implicitly defined answer names. 181 $ans_name = $i; # just number the answers in order 182 $allAnswersCorrectQ = $allAnswersCorrectQ && $answerIsCorrectQ; 183 $printedResponse .= "\n<TR><TD align=left COLSPAN =2><em>Answer $ans_name entered:</em>--> $normalizedSubmittedAnswer <-- "; 184 $printedResponse .= "<B>Correct. </B></TD></TR>" if ($answerIsCorrectQ && $showPartialCorrectAnswers ); 185 $printedResponse .= "<B>Incorrect. </B></TD></TR>" if (!($answerIsCorrectQ) && $showPartialCorrectAnswers); 186 # change 9/2/00 by MEG -- give width in pixels rather than %. 187 # Some browsers break with % widht which is not the standard 188 $printedResponse .= "\n<TR> <TD align=left WIDTH = \"50\" ></TD><TD align=left>$errors</TD></TR>" if ($errors =~ /\w/); 189 190 $printedResponse .= "\n<TR><TD align=left WIDTH = \"50\"></TD> <TD align=left><em>Correct answer:</em> $normalizedCorrectAnswer</TD></TR>" if ($displayCorrectAnswersQ); 191 192 } 193 if ($i == 1) { 194 $printedResponse .= "\n<TR><TD align=left COLSPAN =2><B>The above answer is correct.</B><BR>" if ($allAnswersCorrectQ); 195 $printedResponse .= "\n<TR><TD align=left COLSPAN =2><B>The above answer is NOT correct.</B><BR>" if (!($allAnswersCorrectQ)); 196 } 197 else { 198 $printedResponse .= "\n<TR><TD align=left COLSPAN =2><B>All of the above answers are correct.</B><BR>" if ($allAnswersCorrectQ); 199 $printedResponse .= "\n<TR><TD align=left COLSPAN =2><B>At least one of the above answers is NOT correct.</B><BR>" if (!($allAnswersCorrectQ)); 200 } 201 my $percentCorr = int(100*$rh_problem_result->{score} +.5); 202 203 $printedResponse .="\n<TR><TD align=left COLSPAN =2><B>Your score on this attempt is ${percentCorr}\%.</B><BR>"; 204 $printedResponse .= "\n</table>\n"; 205 # $printedResponse .="\n problem grader is ".$rh_problem_result->{type}." and the score is ".$rh_problem_result->{score}."<BR>\n"; 206 $printedResponse; 207 } 208 209 ########################################################################################### 210 # Previews submitted answers to the problem. Returns a string. # 211 ########################################################################################### 212 213 sub preview_answers { 214 my ($rh_answer_results,$rh_problem_result,$rh_flags) = @_; 215 my @answer_entry_order = @{$rh_flags -> {ANSWER_ENTRY_ORDER} }; 216 my $ANSWER_PREFIX = $rh_flags -> {ANSWER_PREFIX}; 217 my $printedResponse =''; 218 ###### Print appropriate response to submitted answers 219 my ($i,$original_student_ans,$normalizedSubmittedAnswer,$errors,$ans_name,$preview_text_string,$preview_latex_string); 220 my ($ans_evaluator_type, $value_word, $error_word, $show_value); 221 222 $i=0; 223 $printedResponse .= "\n<table border=0 cellpadding=0 cellspacing=0 >\n"; 224 foreach my $key ( @answer_entry_order ) { 225 $i++; 226 $ans_name = $rh_answer_results ->{$key} -> {ans_name}; 227 #$ans_name =~ s/$ANSWER_PREFIX//; # this handles implicitly defined answer names. #commented out by DME 6/6/2000 228 $original_student_ans = $rh_answer_results ->{$key} -> {original_student_ans}; 229 $normalizedSubmittedAnswer = $rh_answer_results ->{$key} -> {student_ans}; 230 $errors = $rh_answer_results ->{$key} -> {ans_message}; 231 $preview_text_string =''; 232 $preview_text_string = $rh_answer_results ->{$key} -> {preview_text_string} 233 if defined $rh_answer_results ->{$key} -> {preview_text_string}; 234 $preview_latex_string =''; 235 $preview_latex_string = $rh_answer_results ->{$key} -> {preview_latex_string} 236 if defined $rh_answer_results ->{$key} -> {preview_latex_string}; 237 $ans_evaluator_type = $rh_answer_results ->{$key} -> {type}; 238 $value_word = 'value:'; 239 $show_value = 0; 240 $show_value = 1 if ((($ans_evaluator_type =~ /number/) and ($normalizedSubmittedAnswer =~ /\w/)) or ($normalizedSubmittedAnswer =~ /^error/)); 241 $show_value = 0 if ($normalizedSubmittedAnswer =~ /^error:\s+empty/); 242 $value_word = '' if ($normalizedSubmittedAnswer =~ /^error/); 243 $error_word = 'error:'; 244 $error_word = '' if ($errors =~ /^error:/); 245 $printedResponse .= "\n<TR><TD align=left>Ans $i </TD>"; 246 #$printedResponse .= "\n<TD align=left><INPUT TYPE=\"text\" NAME=\"${ANSWER_PREFIX}${ans_name}\" VALUE=\"$original_student_ans\" SIZE=70></TD></TR>"; #commented out by DME 6/6/2000 247 $printedResponse .= "\n<TD align=left><INPUT TYPE=\"text\" NAME=\"${ans_name}\" VALUE=\"$original_student_ans\" SIZE=70></TD></TR>"; 248 $printedResponse .= "\n<TR> <TD align=left WIDTH = \"7%\" ></TD><TD align=left>parsed: $preview_text_string</TD></TR>" if ($preview_text_string =~ /\w/); 249 $printedResponse .= "\n<TR> <TD align=left WIDTH = \"7%\" ></TD><TD align=left>${value_word} $normalizedSubmittedAnswer</TD></TR>" if $show_value == 1; 250 $printedResponse .= "\n<TR> <TD align=left WIDTH = \"7%\" ></TD><TD align=left>${error_word} $errors</TD></TR>" if (($errors =~ /\w/) and ($errors ne 'empty')) ; 251 if ($preview_latex_string =~ /\w/) { 252 $printedResponse .= "\n<TR> <TD align=left WIDTH = \"7%\" ></TD><TD align=left>"; 253 $printedResponse .= "\n <APPLET CODE=\"HotEqn.class\" HEIGHT=\"80\" WIDTH=\"500\" ARCHIVE=\"HotEqn.zip\" NAME=\"Equation\" ALIGN=\"middle\" CODEBASE=\"$Global::appletsURL\"> "; 254 $printedResponse .= "\n <PARAM NAME=\"equation\" VALUE=\"$preview_latex_string\"></APPLET></TD></TR> "; 255 } 256 $printedResponse .= "\n<TR Height = 5></TR>"; 257 } 258 259 $printedResponse .= "\n</table>\n"; 260 $printedResponse; 261 } 262 263 264 sub lc_sort { # this sorts strings with letters and number groups, alternately lexigraphically and numerically 265 # (lc stands for library of congress as in QA617.34R45) 266 my($left,$right) = @_; 267 # format "abcd345.57def34ABC"; 268 # string assumed to begin with alpha 269 # string is split into alternating alpha and numeric groups 270 # numeric groups match [\d\.]+ 271 # numeric groups assumed to contain at least one digit, ( a period alone will cause and error) 272 # alpha groups can contain any characters except digits and the period 273 # spaces in alpha groups will cause unexpected behavior 274 # sort is not case sensitive 275 # _ sorts after alpha characters 276 277 # not case sensitive 278 279 my @a = split( /([\d\.]+)/, $left); 280 281 my @b = split( /([\d\.]+)/, $right); 282 283 my $out = undef; 284 my $mode = 0; # even is lexic and odd is numeric 285 my($l,$r); 286 while (@a) { 287 $l = shift @a; 288 $r = shift @b; 289 $out = ($mode++ % 2 == 0) ? uc($l) cmp uc($r) : $l <=> $r; # lexic or numeric compare 290 last unless $out==0; # stop unless $l and $r are different. 291 292 } 293 $out; 294 } 295 296 ##################################################################### 297 # Creates an insert which appears on the probSet page. # 298 ##################################################################### 299 sub createDisplayedInsert 300 { 301 #my ($mode,$setNumber,$fileName,$psvn,$courseName,$printlinesref)= @_; 302 my ($setNumber,$fileName,$psvn,$courseName,$printlinesref)= @_; 303 304 my @printlines=@$printlinesref; 305 my $PROBDIR; 306 307 # if($mode eq "HTML" || $mode eq 'HTML_tth') { 308 # @printlines = &createProblem2($mode,$fileName,$psvn,$courseName,$sourceref); 309 # 310 # } elsif ($mode eq 'Latex2HTML') { 311 #latex2html processing 312 my $coursel2hDirectory = getCoursel2hDirectory(); 313 unless(-e $coursel2hDirectory ) { 314 &createDirectory($coursel2hDirectory, $Global::l2h_set_directory_permission, 315 $Global::numericalGroupID); 316 } 317 318 unless(-e "${coursel2hDirectory}set$setNumber") { 319 &createDirectory("${coursel2hDirectory}set$setNumber",$Global::l2h_set_directory_permission, 320 $Global::numericalGroupID); 321 } 322 323 my $shortFileName = $fileName; 324 $shortFileName =~ s|^.*?([^\/]*)$|$1|; 325 $shortFileName =~ s|\..*$||; 326 $PROBDIR = convertPath("${coursel2hDirectory}set$setNumber/$shortFileName-$psvn/"); 327 if (! -e $PROBDIR) { 328 &l2hcreate($setNumber,$shortFileName,$psvn,$printlinesref); 329 } else { 330 #&attachProbSetRecord($psvn); 331 my $fullFileName = "${Global::templateDirectory}$fileName"; 332 #print "\n\n The full filename is $fullFileName \n\n"; 333 my @probDirStat = stat $PROBDIR; 334 my @sourceFileStat = stat $fullFileName; 335 #print "\n\n The source file age is $sourceFileStat[9] \n\n"; 336 #print "\n\n The prob dir age is $probDirStat[9] \n\n"; 337 if ($sourceFileStat[9] > $probDirStat[9] ) { ## source file is newer 338 rmDirectoryAndFiles($PROBDIR); 339 &l2hcreate($setNumber,$shortFileName,$psvn,$printlinesref); 340 } 341 #else {&createProblem2($mode, $fileName, $psvn,$courseName,$sourceref);} ##initialize problem 342 343 } 344 345 346 open(TEXXX, "${PROBDIR}${psvn}output.html") or 347 wwerror("ERROR: $0", "Can't open ${PROBDIR}${psvn}output.html",'','', ''); 348 @printlines = <TEXXX>; 349 close(TEXXX); 350 # } else { 351 # 352 # @printlines="createDisplayedProblem: Error: Mode is not HTML, HTML_tthHTML_tth or Latex2HTML."; 353 # 354 # 355 # } 356 @printlines; 357 } 358 359 ##do not need this subroutine anymore 360 #sub l2hcreateProb { 361 # my ($setNumber,$probNum,$psvn,$printlinesref)= @_; 362 # #my ($setNumber,$probNum,$psvn,$courseName,$printlinesref)= @_; 363 # #my $mode = 'Latex2HTML'; 364 # 365 # #my @printlines = &createProblem($mode, $probNum, $psvn, $courseName,$sourceref,$refSubmittedAnswers); 366 # #my $printlinesref = \@printlines; 367 # my $tmpDirectory = "tmp/l2h/set$setNumber/$probNum-$psvn/"; 368 # l2hcreate($setNumber,$probNum,$psvn,$printlinesref) 369 #} 370 371 #do not use this subroutine anymore 372 #sub l2hcreateInsert { 373 # my ($setNumber,$shortFileName,$psvn,$printlinesref)= @_; 374 # #my $mode = 'Latex2HTML'; 375 # #my @printlines = &createProblem2($mode, $fileName, $psvn,$courseName,$sourceref); 376 # #my $printlinesref = \@printlines; 377 # #my $shortFileName = $fileName; 378 # #$shortFileName =~ s|^.*?([^\/]*)$|$1|; 379 # #my $tmpDirectory = "tmp/l2h/set$setNumber/$shortFileName-$psvn/"; 380 # l2hcreate($setNumber,$shortFileName,$psvn,$printlinesref) 381 #} 382 383 sub l2hcreate { ## for latex2HTML 96.1 and 98.1 384 my ($setNumber,$probNum,$psvn,$printlinesref) = @_; 385 386 # warn "l2hcreate is being executed displaymacros.pl line ".__LINE__; 387 388 my $PROBDIR = convertPath(&getCoursel2hDirectory."set$setNumber/$probNum-$psvn/"); 389 my $TMPPROBDIR = convertPath(&getCoursel2hDirectory."$probNum-$psvn/"); 390 my $PROBURL = &getCoursel2hURL."set$setNumber/$probNum-$psvn/"; 391 392 &createDirectory($TMPPROBDIR,$Global::l2h_prob_directory_permission,$Global::numericalGroupID) 393 unless(-e "$TMPPROBDIR"); 394 395 open(OUTTEXFILE, ">$TMPPROBDIR${psvn}output.tex") or wwerror($0, "Can't open temporary file $TMPPROBDIR${psvn}output.tex"); 396 397 print OUTTEXFILE &texInput($Global::TEX_PROB_PREAMBLE); 398 print OUTTEXFILE &texInput($Global::TEX_PROB_HEADER); 399 print OUTTEXFILE @$printlinesref; 400 print OUTTEXFILE &texInput($Global::TEX_PROB_FOOTER); 401 close(OUTTEXFILE); 402 403 ## Give this temporary file permission 666 in case the process dies before it it deleted 60 lines further down 404 chmod(0666, "$TMPPROBDIR${psvn}output.tex"); 405 406 ## system("/usr/math/bin/latex2html -init_file ${Global::mainDirectory}latex2html.init -dir $PROBDIR -prefix $psvn ${htmlDirectory}tmp/l2h/${psvn}output.tex > ${htmlDirectory}tmp/l2h/${psvn}l2h.log"); 407 my $latex2HTML_result = &makeL2H($TMPPROBDIR, $psvn) ; 408 warn( "LaTeX2HTML failed. Returned with status: $latex2HTML_result\n" ) if $latex2HTML_result ; 409 410 ##Get rid of all unwanted stuff in html document created by latex2html 411 unless(-e "${TMPPROBDIR}${psvn}output.html") { 412 warn "Can't rename ${TMPPROBDIR}${psvn}output.html"; 413 return (0); ### there was a failure in latex2html processing 414 ### we just give a warning so that so that l2hPrecreateSet.pl can continue 415 } 416 417 rename("${TMPPROBDIR}${psvn}output.html","${TMPPROBDIR}${psvn}output.html.org") or 418 warn "Can't rename ${TMPPROBDIR}${psvn}output.html at ". __LINE__; 419 open(TEXORG, "${TMPPROBDIR}${psvn}output.html.org") or 420 warn "Can't open ${TMPPROBDIR}${psvn}output.html.org"; 421 my @l2hOutputArray; 422 423 424 425 426 BLK: { # This is protection to make absolutely sure that the line separater is set properly. 427 # It's still a mystery as to where this becomes defined to be something else. 428 local($/); 429 $/ = "\n"; 430 @l2hOutputArray = <TEXORG>; 431 432 433 } 434 435 close(TEXORG); 436 open(TEXNEW, ">${TMPPROBDIR}${psvn}output.html") or 437 wwerror($0, "Can't open ${TMPPROBDIR}${psvn}output.html",'','', ''); 438 439 440 foreach (@l2hOutputArray) { 441 if($_ =~ /^<META/) {next;} 442 if($_ =~ /^<!DOCTYPE HTML PUBLIC/) {next;} 443 if($_ =~ /^<HTML>/) {next;} 444 if($_ =~ /^<HEAD>/) {next;} 445 if($_ =~ /^<TITLE>/) {next;} 446 if($_ =~ /^<LINK REL/) {next;} 447 if($_ =~ /^<\/HEAD>/) {next;} 448 if($_ =~ /^<BODY/) {next;} 449 if($_ =~ /^<\/BODY>/) {next;} 450 if($_ =~ /^<\/HTML>/) {next;} 451 if($_ =~ /^<BR> <HR>/) {next;} 452 453 print TEXNEW ; 454 } 455 456 457 close(TEXNEW); 458 459 ## Now do global multiline changes on whole file 460 461 open(TEXNEW, "${TMPPROBDIR}${psvn}output.html") or 462 wwerror("$0", "Can't open ${TMPPROBDIR}${psvn}output.html",'','', ''); 463 @l2hOutputArray = <TEXNEW>; 464 close(TEXNEW); 465 my $l2hOutputString = join('',@l2hOutputArray); 466 467 ## make gif images created by latex2html locatable by server 468 ## NOTE: $htmlURL is defined in webworkCourse.ph . Often this will 469 ## will be a link appearing in a public_html_docs directory. 470 ## The $htmlURL, any links, and the next line must be coordinated. 471 472 $l2hOutputString =~ s|${psvn}img|${PROBURL}${psvn}img|g; 473 474 ## remove multiline comments 475 $l2hOutputString =~ s|<!--.*?-->\n||sg; 476 477 open(TEXNEW, ">${TMPPROBDIR}${psvn}output.html") or 478 wwerror("$0", "Can't open ${TMPPROBDIR}${psvn}output.html",'','', ''); 479 print TEXNEW $l2hOutputString; 480 close(TEXNEW); 481 482 ## remove unneeded files 483 484 unless ($debug) {unlink("${TMPPROBDIR}${psvn}output.html.org");} 485 unless ($debug) {unlink(<${TMPPROBDIR}*images.*>);} 486 unless ($debug) {unlink(<${TMPPROBDIR}.*.db>);} 487 unless ($debug) {unlink(<${TMPPROBDIR}*.db>);} 488 unless ($debug) {unlink(<${TMPPROBDIR}IMG_PARAMS.*>);} 489 unless ($debug) {unlink(<${TMPPROBDIR}*.pl>);} 490 unless ($debug) {unlink(<${TMPPROBDIR}*.css>);} 491 unless ($debug) {unlink("${TMPPROBDIR}index.html");} 492 unless ($debug) {unlink("${TMPPROBDIR}${psvn}output.tex");} 493 unless ($debug) {unlink("${TMPPROBDIR}${psvn}l2h.log");} 494 unless ($debug) { 495 my @allfiles = (); 496 opendir( DIRHANDLE, "$TMPPROBDIR") || warn qq/Can't read directory $TMPPROBDIR $!/; 497 @allfiles = map "$TMPPROBDIR$_", grep( /^l2h/, readdir DIRHANDLE); 498 closedir(DIRHANDLE); 499 my $l2hTempDir = $allfiles[0]; 500 if (defined $l2hTempDir) { 501 unlink(<$l2hTempDir/*>); 502 rmdir ($l2hTempDir); 503 } 504 } 505 506 ## change permission and group on remaining files 507 chmod($Global::l2h_data_permission, glob("${TMPPROBDIR}*")); 508 chown(-1,$Global::numericalGroupID,glob("${TMPPROBDIR}*")); 509 510 ## Now that all the processing has been done, rename the $TMPPROBDIR TO $PROBDIR 511 512 rename("$TMPPROBDIR","$PROBDIR") or 513 warn "Can't rename the temporary problem directory:\n $TMPPROBDIR to $PROBDIR\n at displayMacros.pl , line: " . __LINE__ ; 514 515 } 516 517 518 ######################################################################################################### 519 ##Subroutine that makes answers sticky in l2h mode # 520 # # 521 # INPUT: $rh_submittedAnswers Reference to a hash containing the answers submitted # 522 # $ra_printLines Reference to an array containing the (HTML) text to be output # 523 # $rh_flags Reference to a hash containing flags; specifically a # 524 # reference to an array containing the answer field labels # 525 # # 526 # OUTPUT: @printLines An array containing the (modified) text to be output # 527 # # 528 # OVERVIEW: l2h_sticky_answers is given HTML text, a list of submitted answers, and a list of # 529 # answer field labels. Its job is to retain the user's answers between submissions # 530 # when in typeset mode (this is handled elsewhere in the text modes). Basically, its # 531 # job is to act as a "filter" for the HTML text, replacing the answer fields that have # 532 # been reset with fields containing the previously entered answers, returning the # 533 # modified text. A brief high-level overview of the algorithm follows: # 534 # # 535 # ALGORITHM: The references are first dereferenced. The incoming text is first joined into # 536 # one string. It is then split up again, but not by line. Rather, the text is split # 537 # such that each array entry is either text which can be ignored, or a single # 538 # <INPUT...> tag. Each entry is then processed. If it is an <INPUT> tag, then it # 539 # must be checked for the presence of each answer field label for which a value was # 540 # submitted (there are many <INPUT> fields which are not answer fields, so we can't # 541 # assume that consecutive <INPUT> fields correspond to consecutive answer labels). # 542 # If a label is found, the blank value space is replaced with the appropriate # 543 # submitted answer (note that we can assume that there is a one-to-one correspondence # 544 # between answer labels and submitted answers; this is guaranteed by the specs). Radio # 545 # buttons and checkboxes are handled specially; see below. The modified text is then # 546 # added to the output string, which is split on a placeholder such that the output # 547 # array has the same number of entries as the input array (this is not required, but # 548 # might avoid some subtle bug in the future). # 549 # # 550 # NOTE: The specifications seem to require that the input text array consist of one # 551 # field for each line of text. However, it appears that the input is actually one # 552 # field, with newline characters separating lines. This function should accept # 553 # either form of input, although the "correct" form of one field per line has not # 554 # been tested. It is possible that, if input is received in this form AND the # 555 # newline characters have been truncated, the output could be garbled. # 556 # # 557 # --David Etlinger 6/7/2000 # 558 # # 559 # ADDED: Added a few lines of code to properly handle radio buttons. Checkboxes still need # 560 # to be implemented. # 561 # --David Etlinger 6/14/2000 # 562 # # 563 # ADDED: Added code to handle checkboxes. This is complicated because the submitted checkboxes # 564 # are originally stored as a single string with "\0" as a delimiter. If the input type # 565 # is determined to be checkboxes, the string is first split into an array. A hash key # 566 # in a special checkbox array is then made to point to the array. This is done because # 567 # there might be more than one checkbox set in a single question. Each time an input line # 568 # of type checkbox appears, the next value in this array is popped into a temp variable. # 569 # If it is determined that the line being processed corresponds to this value, the line # 570 # is processed (made "sticky"); otherwise, the value is pushed back on the array. The # 571 # fact that the number of checked cehckboxes is known but the total number of checkboxes # 572 # is not means that a given line of input type checkbox might or might not correspond # 573 # to the next value in the checkbox array. (I hope this explanation is clear enough!) # 574 # --David Etlinger 6/28/2000 # 575 ######################################################################################################### 576 577 sub l2h_sticky_answers { 578 my ( $rh_submittedAnswers, $ra_printLines, $rh_flags ) = @_; 579 580 #warn ("rh_submittedAnswers = \@rh_submittedAnswers"); 581 #warn ("ra_printLines = \@{ra_printLines}"); 582 #warn ("rh_flags = \@{rh_flags}"); 583 584 my %submittedAnswers = %{$rh_submittedAnswers}; 585 my @printLines = @{$ra_printLines}; 586 my @answerLabels = @{$rh_flags -> {ANSWER_ENTRY_ORDER}}; 587 588 my $line; # holds the text of each line 589 my $label; # holds each answer label 590 my $counter = 0; # holds the index of the current answer 591 my $output; # holds the text the subroutine returns 592 593 my $answer_value; 594 595 my %checkboxAns; # holder for the checkbox multi-part answers 596 my $nextCheckboxAns; # temp holder for the next checkbox answer to be processed 597 598 my $placeholder = "\x253"; # unused hex character to join text lines with 599 600 #first, convert the array of text lines to one string... 601 my $text = join( "$placeholder", @printLines ); 602 603 #then, split it such that a line consists of either text 604 #or a single <INPUT> tag (case insensitive; note also that 605 #whitespace within the <INPUT> tag is accounted for). 606 # NOTE -- the regular expression searches for "<", then any 607 # amount of whitespace, then "INPUT", then any number of 608 # characters that aren't ">", then ">". I think that instead of 609 # searching for characters that aren't ">", I could have instead 610 # searched to match a minimal number of characters (using ?), and 611 # then ">". I don't know regular expressions well enough to tell 612 # if this might lead to some subtle difference. 613 my @textLines = split( m|(<\s*INPUT[^>]*>)|is, $text ); 614 #my @textLines = split( m|(<\s*INPUT.*?>)|is, $text ); 615 616 foreach $line ( @textLines ) { 617 if( $line =~ m|<\s*INPUT|i ) { 618 foreach $label ( @answerLabels ) { 619 next unless exists( $submittedAnswers{$label} ); # skip if no answer was submitted. 620 if( $line =~ m|NAME\s*=\s*"$label"|i ) { 621 if( $line =~ m|TYPE\s*=\s*RADIO|i ) { #handle radio buttons 622 $line =~ s|VALUE\s*=\s*"$submittedAnswers{$label}"|VALUE = "$submittedAnswers{$label}" CHECKED|i; 623 } 624 elsif( $line =~ m|TYPE\s*=\s*CHECKBOX|i ) { 625 #make the hash key point to an anonymous array 626 $checkboxAns{$label} = [ split( "\0", $submittedAnswers{$label} ) ] if not exists( $checkboxAns{$label} ); 627 if( defined $checkboxAns{$label}[0] ) { 628 $nextCheckboxAns = shift @{$checkboxAns{$label}}; 629 if( $line !~ s|VALUE\s*=\s*"$nextCheckboxAns"|VALUE = "$nextCheckboxAns" CHECKED|i ) { 630 unshift( @{$checkboxAns{$label}}, $nextCheckboxAns ); #put the unused answer back on the list 631 } 632 } 633 } 634 else { 635 # we'll assume this is something else, like one or more fields. 636 # if it's several fields, we need to take only one answer at a time 637 # \0 are used to delimeter between entries. 638 if ($submittedAnswers{$label} =~ /\0/ ) { 639 my @answers = split("\0", $submittedAnswers{$label}); 640 $answer_value = shift(@answers); # use up the first answer 641 $submittedAnswers{$label}=join "\0", @answers; # store the rest 642 $answer_value= '' unless defined($answer_value); 643 644 } 645 else { 646 $answer_value = $submittedAnswers{$label}; 647 } 648 649 $line =~ s|VALUE\s*=\s*""|VALUE = "$answer_value"|i; 650 } 651 } 652 } 653 } #end if test for "<INPUT" 654 655 $output .= $line; 656 } #end foreach 657 658 @printLines = split( m|$placeholder|, $output ); 659 return @printLines; 660 } #end l2h_sticky_answers() 661 662 ## This is the old system (but newer than the one below). 663 ## It has been replaced for two reasons: 664 ## 1) It is complicated and difficult to understand or modify 665 ## 2) It does not work for several situations that rarely come up, 666 ## but must be handled properly. Specifically, it doesn't handle 667 ## text with more than one <INPUT> tag on a given line very well. 668 ## there are probably other problems, but that is the biggest. 669 ## --DME 6/7/2000 670 # # the following doubly nested loop iterates over each line, 671 # # and for each line searches for each answer label. Technically, 672 # # it might have been faster to join each entry in @printlines 673 # # into one string, search on that, and split it back up, but I 674 # # felt that the slight theoretical speed gain was not worth the 675 # # added complexity. 676 # warn "answerLabels = @answerLabels"; #DEBUG 677 # foreach $line ( @printLines ) { 678 # warn "Line is $line"; #DEBUG 679 # foreach $label ( @answerLabels ) { 680 # if( $line =~ m|<INPUT TYPE=TEXT.*NAME="$label| ) { 681 # while ($line =~ /VALUE = ""/) { 682 # # Put trailing space in displayed answer so that while loop will 683 # # always end. We are using the form of the s/// operator which 684 # # evaluates its right hand side 685 # $line =~ s|NAME="$label" VALUE = ""| 686 # $counter++; 687 # $submittedAnswers[$counter]=" " unless defined ($submittedAnswers[$counter]) 688 # && not $submittedAnswers[$counter] =~ /^\s*$/; 689 # qq{ NAME="$label" VALUE = "$submittedAnswers[$counter]" } |e; 690 # # This insures that in VALUE = "$submittedAnswers[$counter]" 691 # # the quantity $submittedAnswers[$counter] 692 # # is never empty. This is required in order to terminate the loop. 693 # } #end while 694 # push( @output, $line ); 695 # } #end if 696 # else { 697 # push( @output, $line ); 698 # } 699 # } #end foreach over @answerLabels 700 # } #end foreach over @printLines 701 # 702 # @printLines = @output; 703 # } #end outer if 704 # 705 # return @printLines; 706 # } #end l2h_sticky_answers() 707 708 ##subroutine that makes answers sticky in l2h mode 709 # this is an old version of this routine, which assumes (incorrectly) 710 # that answer labels begin with "AnSwEr". I've left it here just in case... 711 # DME 6/6/2000 712 #sub l2h_sticky_answers { 713 # my ($refSubmittedAnswers, $refprintlines)=@_; 714 # my @printlines=@$refprintlines; 715 # if ((@{$refSubmittedAnswers}!=0)) { 716 # my $line; 717 # my @output=(); 718 # foreach $line (@printlines) { 719 # if ($line =~ m|<INPUT TYPE=TEXT.*NAME="AnSwEr|) { 720 # #print "<P>line doesn't exists<P>\n" unless defined($line); 721 # while ($line =~ /VALUE = ""/) { 722 # ## Put trailing space in displayed answer so that while loop will 723 # ## always end. We are using the form of the s/// operator which evaluates its right hand side 724 # $line =~ s|NAME="AnSwEr(\d*)" VALUE = ""| 725 # my $tttemp = $1; 726 # ${$refSubmittedAnswers}[$tttemp-1]=" " unless defined (${$refSubmittedAnswers}[$tttemp-1]) 727 # && not ${$refSubmittedAnswers}[$tttemp-1] =~ /^\s*$/; 728 # 729 # qq{ NAME="AnSwEr$tttemp" VALUE = "${$refSubmittedAnswers}[$tttemp-1]" } |e; 730 # # This insures that in VALUE = "${$refSubmittedAnswers}[$tttemp-1]" the quantity ${$refSubmittedAnswers}[$tttemp-1] 731 # # is never empty. This is required in order to terminate the loop. 732 # } 733 # push(@output, $line); 734 # } 735 # else { 736 # push(@output, $line); 737 # } 738 # } 739 # 740 # @printlines = @output; 741 # } 742 # 743 # @printlines; 744 #} 745 746 ##subroutine that updates current keys in the l2h mode 747 748 # sub l2h_update_keys { 749 # my ($sessionKey, $refprintlines)= @_; 750 # my @printlines=@$refprintlines; 751 # my $line; 752 # my @output=(); 753 # #my $sessionKey = $main::sessionKey; 754 # warn "hi lines = ",join("",@printlines); 755 # foreach $line (@printlines) { 756 # if ($line =~ m|^\s*<A(.*?)\&key=[^&]*&user|) { #<A.*&key=.*?&user 757 # #grab the session key from the CGI input or make it blank 758 # $line =~ s|^\s*<A(.*?)&key=[^&]*&user|<A$1&key=$sessionKey&user|; 759 # warn "line = $line<BR>"; 760 # push(@output, $line); 761 # }else{ 762 # push(@output, $line); 763 # } 764 # 765 # } 766 # @printlines; 767 # 768 # } 769 770 771 sub makeL2H { 772 my ($TMPPROBDIR,$psvn) =@_; 773 $ENV{PATH} .= "$Global::extendedPath"; 774 if($Global::externalLaTeX2HTMLVersion eq "98.1p1") { 775 system("$Global::externalLaTeX2HTMLPath -no_math -init_file $Global::externalLaTeX2HTMLInit -dir $TMPPROBDIR -prefix $psvn $TMPPROBDIR${psvn}output.tex > $TMPPROBDIR${psvn}l2h.log 2>&1"); 776 } elsif($Global::externalLaTeX2HTMLVersion eq "96.1") { 777 system("$Global::externalLaTeX2HTMLPath -init_file $Global::externalLaTeX2HTMLInit -dir $TMPPROBDIR -prefix $psvn $TMPPROBDIR${psvn}output.tex > $TMPPROBDIR${psvn}l2h.log"); 778 } else { 779 die "Unknown LaTeX2HTML version: \$Global::externalLaTeX2HTMLVersion = $Global::externalLaTeX2HTMLVersion"; 780 } 781 } 782 783 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |