6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 function removedoublecr($filename) {
11 // This function will adjust a file in roughly Aiken style by replacing extra newlines with <br/> tags
12 // so that instructors can have newlines wherever they like as long as the overall format is in Aiken
14 $filearray = file($filename);
15 /// Check for Macintosh OS line returns (ie file on one line), and fix
16 if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
17 $outfile = explode("\r", $filearray[0]);
19 $outfile = $filearray;
22 foreach ($outfile as $line) {
23 // remove leading and trailing whitespace
25 // check it's length, if 0 do not output... if it is > 0 output
26 if ($line[0] == "\n" OR strlen($line)==0 ) {
27 if (count($outarray) ) {
28 // get the last item in the outarray
29 $cur_pos = (count($outarray) - 1);
30 $outarray[$cur_pos] = trim($outarray[$cur_pos])."<br/>\n";
34 $length=strlen($line);
39 if ($line[$length-1] == "\n") {
43 $outarray[] = $line."\n";
48 // output modified file to original
49 if ( is_writable($filename) ) {
51 if (! $handle =fopen ($filename ,'w' )) {
52 echo "Cannot open file ($filename)" ;
55 foreach ($outarray as $outline) {
56 fwrite($handle, $outline);
66 function importmodifiedaikenstyle($filename) {
67 // This function converts from Brusca style to Aiken
68 $lines = file($filename);
72 foreach ($lines as $line) {
73 // strip leading and trailing whitespace
75 // add a space at the end, quick hack to make sure words from different lines don't run together
78 // ignore lines less than 2 characters
79 if (strlen($line) < 2) {
84 // see if we have the answer line
86 if ($line[0] == '*') {
94 $leadin = substr($line, 0,2);
95 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) {
97 // re-add newline to indicate end of previous question/response
98 if (count($outlines)) {
99 $cur_pos = (count($outlines) - 1);
100 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
105 // make character uppercase
106 $line[0]=strtoupper($line[0]);
108 // make entry followed by '.'
111 elseif ( ($responses AND $answer_found) OR (count($outlines)<=1) ) {
112 // we have found responses and an answer and the current line is not an answer
124 // re-add newline to indicate end of previous question/response
125 if (count($outlines)) {
126 $cur_pos = (count($outlines) - 1);
127 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
130 // this next ugly block is to strip out the numbers at the beginning
132 // this probably could be done cleaner... it escapes me at the moment
133 while ($line[$np] == '0' OR $line[$np] == '1' OR $line[$np] == '2'
134 OR $line[$np] == '3' OR $line[$np] == '4' OR $line[$np] == '5'
135 OR $line[$np] == '6' OR $line[$np] == '7' OR $line[$np] == '8'
136 OR $line[$np] == '9' ) {
139 // grab everything after '###.'
140 $line = substr($line, $np+
1, strlen($line));
142 if ($responses AND $answer_found) {
145 $answer = strtoupper($answer);
146 $outlines[] = "ANSWER: $answer\n\n";
151 if (substr($line, 0, 14) == 'ANSWER CHOICES') {
152 // don't output this line
157 } // close for each line
159 // re-add newline to indicate end of previous question/response
160 if (count($outlines)) {
161 $cur_pos = (count($outlines) - 1);
162 $outlines[$cur_pos] = $outlines[$cur_pos]."\n";
165 // output the last answer
166 $answer = strtoupper($answer);
167 $outlines[] = "ANSWER: $answer\n\n";
169 // output modified file to original
170 if ( is_writable($filename) ) {
171 if (! $handle =fopen ($filename ,'w' )) {
172 echo "Cannot open file ($filename)" ;
175 foreach ($outlines as $outline) {
176 fwrite($handle, $outline);