rendered paste body<?php include "config.php" ; function answer_hash ($answer) { $hdg = array("0", "1", "2", "3", "4", "5", "6", "7" , "8", "9", "A", "B", "C", "D", "E", "F") ; $ans = strtolower($answer) ; $ans = preg_replace("/^\s*|\s*$/", "", $ans) ; $ans = preg_replace("/\s+/", " ", $ans) ; //$hsh = 23232323 ; $hsh = "" ; for ($i=0; $i<strlen($ans); $i++) { $ltr = ord($ans[$i]) ; //if ($ltr >= 97 && $ltr <= 122 || $ltr == 32) { //$hsh = ($hsh*23+floor($hsh / 10000000)+$ltr)%10000000 ; $hsh = $hsh . $hdg[floor($ltr/16)] . $hdg[$ltr%16] ; //} } return $hsh ; } function load_exam_script($scriptFile) { global $config ; $fh = fopen($scriptFile, 'r') or die("Can't open file"); $field_count = 0 ; $answer_table= "" ; $starter_table = "" ; $page_count= 0 ; echo "\n\n<div id='page_0'>\n" ; while ($line= fgets($fh)) { if (!preg_match("/^#/", $line)) { # ignore comment lines # chop newlines $line = preg_replace("/[\r\n]/", "", $line) ; # replace titles if (preg_match("/^\(t\s*(.*)\s*t\)\s*$/", $line, $matches)) { $page_count++ ; $line = preg_replace("/^\(t\s*(.*)\s*t\)\s*$/", "\n</div><div id='page_".$page_count."' style='display:none'>\n<h1>$1</h1>", $line) ; $answer_table .= "\n" ; $starter_table .= ", ".($field_count+1) ; } # replace images $line = preg_replace("/\(i\s*(\S*)\s*i\)/", '<img src="'.$config{'image_dir'}.'/$1" width="150" />', $line) ; # replace videos $line = preg_replace("/\(v\s*(\S*)\s*v\)/", "<script>xbEmbedVideo('vid','".$config{'video_dir'}."/$1');</script>\n", $line) ; $line = preg_replace("/\(y\s*(\S*)\s*y\)/", "<object width=\"300\" height=\"300\"><param name=\"movie\" value=\"$1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"$1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"300\" height=\"300\"></embed></object>", $line) ; # replace choices ---------------------------------------- if (preg_match("/(.*)\(c\s*(.*\S)\s*c\)/", $line, $matches)) { $field_count++ ; $choice = '<div id="answer_'.$field_count.'_box" name="answer_'.$field_count.'_box">' ; foreach (preg_split("/\s+/",preg_quote($matches[2])) as $opt) { if (substr($opt,0,1) == '&') { # right option $opt = substr($opt,1) ; $answer_table .= ", '".answer_hash($opt)."'" ; } $choice .= " ".$matches[1] . '<input id="answer_'.$field_count.'_radio" ' . 'name="answer_'.$field_count.'_radio" ' . 'type="radio" style="border:none" value="'.$opt.'" ' . 'onFocus="return rbutFocused('.$field_count.')" ' . 'onClick="document.form1.answer_'.$field_count.'.value = this.value ; return rbutChanged('.$field_count.')" ' . '>' . $opt . "</input><br>\n" ; } $choice .= '<input type="hidden" ' . 'id= "answer_'.$field_count.'"' . 'name= "answer_'.$field_count.'"' . 'value=""></input></div>' ; $line = preg_replace("/(.*)\(c\s*(.*\S)\s*c\)/" , $choice , $line) ; } # replace choices ---------------------------------------- /* if (preg_match("/(.*)\(c\s*(.*\S)\s*c\)/", $line, $matches)) { $field_count++ ; $choice = '<div id="answer_'.$field_count.'_box" name="answer_'.$field_count.'_box">' ; foreach (preg_split("/\s+/",preg_quote($matches[2])) as $opt) { if (substr($opt,0,1) == '&') { # right option $opt = substr($opt,1) ; $answer_table .= ", '".answer_hash($opt)."'" ; } $opt=str_replace("_"," ",$opt); $choice .= " ".$matches[1] . '<input id="answer_'.$field_count.'_radio" ' . 'name="answer_'.$field_count.'_radio" ' . 'type="radio" style="border:none" value="'.$opt.'" ' . 'onFocus="return rbutFocused('.$field_count.')" ' . 'onClick="document.form1.answer_'.$field_count.'.value = this.value ; return rbutChanged('.$field_count.')" ' . '>' . $opt . "</input><br>\n" ; } $choice .= '<input type="hidden" ' . 'id= "answer_'.$field_count.'"' . 'name= "answer_'.$field_count.'"' . 'value=""></input></div>' ; $line = preg_replace("/(.*)\(c\s*(.*\S)\s*c\)/" , $choice , $line) ; } */ # replace textboxes ---------------------------------------- //2 /*echo "bob"; $text_boxes= explode("(b",$line); print $text_boxes[0]; if(count($text_boxes)>0) { //$line=""; } for ($i=0; $i<count($text_boxes); $i++) { $l="(b".$text_boxes[$i]; if (preg_match("/\(b\s*(.*\S)\s*b\)/", $l, $match)) { $field_count++ ; $l = preg_replace("/\(b\s*(.*\S)\s*b\)/" , '<input type="text" size="'.strlen($match[1]).'" ' . 'name="answer_'.$field_count.'" ' . 'id="answer_'.$field_count.'" ' . 'readonly="readonly" ' . 'style="background:#ccf" ' . 'onFocus="return tboxFocused('.$field_count.')" ' . 'onBlur="return tboxBlurred('.$field_count.')" ' . 'onKeyPress="return tboxKeypressed(event)" />' , $l) ; $answer_table .= ", '".answer_hash($match[1])."'" ; } # translate whitespace $l= preg_replace("/\s\s/", " ", $l) ; $line.=$l; } echo $line."<br />\n";*/ # replace textboxes ---------------------------------------- $text_matched=0;// while($text_matched==0) // { $matches=true; $max_per_line=15;for($i=0;$i<$max_per_line;$i++) { // preg_match("/\(b\s*(.[^)]*\S)\s*b\)/", $line, $match) if (preg_match("/\(b\s*(.[^)]*\S)\s*b\)/", $line, $match)) { $match[1]=trim($match[1]," "); $field_count++ ; $line = str_replace("(b ".$match[1]." b)" , '<input type="text" size="'.strlen($match[1]).'" ' . 'name="answer_'.$field_count.'" ' . 'id="answer_'.$field_count.'" ' . 'readonly="readonly" ' . 'style="background:#ccf" ' . 'onFocus="return tboxFocused('.$field_count.')" ' . '' . 'onKeyPress="return tboxKeypressed(event)" />' , $line) ; $answer_table .= ", '".answer_hash($match[1])."'" ; } } // } # translate whitespace $line = preg_replace("/\s\s/", " ", $line) ; echo $line."<br />\n"; } } fclose($fh); echo "</div>\n\n" ;echo "<div id='finish' align=center> </div>"; echo "<script><!--\n" ; echo "ahs = [''".$answer_table."] ;\n" ; echo "stt = [0".$starter_table.", ahs.length] ;\n" ; echo "num_pages=".$page_count." ;\n" ; echo "--></script>\n\n" ; } echo "<div id='results' style='display:none'>"; echo "</div>"; ?>