3 function removedoublecr($filename) {
4 // This function will adjust a file in roughly Aiken style by replacing extra newlines with <BR> tags
5 // so that instructors can have newlines wherever they like as long as the overall format is in Aiken
7 $filearray = file($filename);
8 /// Check for Macintosh OS line returns (ie file on one line), and fix
9 if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
10 $outfile = explode("\r", $filearray[0]);
12 $outfile = $filearray;
15 foreach ($outfile as $line) {
16 // remove leading and trailing whitespace
18 // check it's length, if 0 do not output... if it is > 0 output
19 if ($line[0] == "\n" OR strlen($line)==0 ) {
20 if (count($outarray) ) {
21 // get the last item in the outarray
22 $cur_pos = (count($outarray) - 1);
23 $outarray[$cur_pos] = trim($outarray[$cur_pos])."<br>\n";
27 $length=strlen($line);
32 if ($line[$length-1] == "\n") {
36 $outarray[] = $line."\n";
41 // output modified file to original
42 if ( is_writable($filename) ) {
44 if (! $handle =fopen ($filename ,'w' )) {
45 echo "Cannot open file ($filename)" ;
48 foreach ($outarray as $outline) {
49 fwrite($handle, $outline);
59 function importmodifiedaikenstyle($filename) {
60 // This function converts from Brusca style to Aiken
61 $lines = file($filename);
65 foreach ($lines as $line) {
66 // strip leading and trailing whitespace
68 // add a space at the end, quick hack to make sure words from different lines don't run together
71 // ignore lines less than 2 characters
72 if (strlen($line) < 2) {
77 // see if we have the answer line
79 if ($line[0] == '*') {
87 $leadin = substr($line, 0,2);
88 if (strpos(".A)B)C)D)E)F)G)H)I)J)a)b)c)d)e)f)g)h)i)j)A.B.C.D.E.F.G.H.I.J.a.b.c.d.e.f.g.h.i.j.", $leadin)>0) {
90 // re-add newline to indicate end of previous question/response
91 if (count($outlines)) {
92 $cur_pos = (count($outlines) - 1);
93 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
98 // make character uppercase
99 $line[0]=strtoupper($line[0]);
101 // make entry followed by '.'
104 elseif ( ($responses AND $answer_found) OR (count(outlines
)<=1) ) {
105 // we have found responses and an answer and the current line is not an answer
117 // re-add newline to indicate end of previous question/response
118 if (count($outlines)) {
119 $cur_pos = (count($outlines) - 1);
120 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
123 // this next ugly block is to strip out the numbers at the beginning
125 // this probably could be done cleaner... it escapes me at the moment
126 while ($line[$np] == '0' OR $line[$np] == '1' OR $line[$np] == '2'
127 OR $line[$np] == '3' OR $line[$np] == '4' OR $line[$np] == '5'
128 OR $line[$np] == '6' OR $line[$np] == '7' OR $line[$np] == '8'
129 OR $line[$np] == '9' ) {
132 // grab everything after '###.'
133 $line = substr($line, $np+
1, strlen($line));
135 if ($responses AND $answer_found) {
138 $answer = strtoupper($answer);
139 $outlines[] = "ANSWER: $answer\n\n";
144 if (substr($line, 0, 14) == 'ANSWER CHOICES') {
145 // don't output this line
150 } // close for each line
152 // re-add newline to indicate end of previous question/response
153 if (count($outlines)) {
154 $cur_pos = (count($outlines) - 1);
155 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
158 // output the last answer
159 $answer = strtoupper($answer);
160 $outlines[] = "ANSWER: $answer\n\n";
162 // output modified file to original
163 if ( is_writable($filename) ) {
164 if (! $handle =fopen ($filename ,'w' )) {
165 echo "Cannot open file ($filename)" ;
168 foreach ($outlines as $outline) {
169 fwrite($handle, $outline);