Annotation of loncom/publisher/testbankimport.pm, revision 1.14
1.3 albertel 1: # Handler for parsing text upload problem descriptions into .problems
1.14 ! raeburn 2: # $Id: testbankimport.pm,v 1.13 2008/04/17 15:58:45 raeburn Exp $
1.3 albertel 3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
1.1 raeburn 27: package Apache::testbankimport;
28:
1.3 albertel 29: use strict;
30: use Apache::Constants qw(:common :http :methods);
31: use Apache::loncacc;
32: use Apache::loncommon();
33: use Apache::lonnet;
34: use HTML::Entities();
35: use Apache::lonlocal;
36: use Apache::lonupload;
37: use File::Basename();
1.11 albertel 38: use LONCAPA();
1.1 raeburn 39:
40: # ---------------------------------------------------------------- Display Control
41: sub display_control {
42: # figure out what page we're on and where we're heading.
1.6 albertel 43: my $page = $env{'form.page'};
44: my $command = $env{'form.go'};
1.1 raeburn 45: my $current_page = &calculate_page($page,$command);
46: return $current_page;
47: }
48:
49: # CALCULATE THE CURRENT PAGE
50: sub calculate_page($$) {
51: my ($prev,$dir) = @_;
52: return 0 if $prev eq ''; # start with first page
53: return $prev + 1 if $dir eq 'NextPage';
54: return $prev - 1 if $dir eq 'PreviousPage';
55: return $prev if $dir eq 'ExitPage';
56: return 0 if $dir eq 'BackToStart';
57: }
58:
59: # ---------------------------------------------------------------- Jscript One
60:
61: sub jscript_one {
62: my $jsref = shift;
63: $$jsref = <<"END_SCRIPT";
64: function verify() {
65: if ((document.forms.display.blocks.value == "") || (!document.forms.display.blocks.value) || (document.forms.display.blocks.value == "0")) {
66: alert("You must enter the number of blocks of questions of a given question type. This number must be 1 or more.")
67: return false
68: }
69: if (document.forms.display.qnumformat.options[document.forms.display.qnumformat.selectedIndex].value == "-1") {
70: alert("You must select the format used for the question number, e.g., (1), 1., (1, or 1).")
71: return false
72: }
73: return true
74: }
75: function nextPage() {
76: if (verify()) {
77: document.forms.display.go.value="NextPage"
78: document.forms.display.submit()
79: }
80: }
81: function backPage() {
82: document.forms.display.go.value="PreviousPage"
83: document.forms.display.submit()
84: }
85: function setElements() {
86: var iter = 0
87: var selParam = 0
88: END_SCRIPT
1.6 albertel 89: if (exists($env{'form.blocks'}) ) {
1.1 raeburn 90: $$jsref .= qq|
1.6 albertel 91: document.forms.display.blocks.value = $env{'form.blocks'}\n|;
92: } elsif (exists($env{'form.qnumformat'}) ) {
1.1 raeburn 93: $$jsref .= <<"TO_HERE";
94: for (iter=0; iter<document.forms.display.qnumformat.length; iter++) {
1.6 albertel 95: if(document.forms.display.qnumformat.options[iter].value == "$env{'form.qnumformat'}") {
1.1 raeburn 96: selParam = iter
97: }
98: }
99: document.forms.display.qnumformat.selectedIndex = selParam
100: TO_HERE
101: }
102: $$jsref .= qq|
103: }
104: |;
105: }
106:
107: # ---------------------------------------------------------------- Jscript Two
108: sub jscript_two {
109: my ($jsref,$qcount) = @_;
110: my $blocks = 0;
1.6 albertel 111: if ( exists( $env{'form.blocks'}) ) {
112: $blocks = $env{'form.blocks'};
1.1 raeburn 113: }
114: $$jsref = <<"END_SCRIPT";
115: function verify() {
116: var poolForm = document.forms.display
117: var curmax = 0
118: var curmin = 0
119: for (var i=0; i<$blocks; i++) {
120: var iter = i+1
121: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "MC") {
122: if (poolForm.elements[5*i+4].selectedIndex == 0) {
123: alert ("You must choose the foil labelling format in Multiple Choice questions")
124: return false
125: }
126: }
127: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "MA") {
128: if (poolForm.elements[5*i+4].selectedIndex == 0) {
129: alert ("You must choose the foil labelling format in Multiple Answer questions")
130: return false
131: }
132: if (poolForm.elements[5*i+5].selectedIndex == 0) {
133: alert ("You must choose the answer format in Multiple Answer questions")
134: return false
135: }
136: }
137: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "FIB") {
138: if (poolForm.elements[5*i+5].selectedIndex == 0) {
139: alert ("You must choose the answer format in Fill-in-the-blank questions")
140: return false
141: }
142: }
143: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "TF") {
144: if (poolForm.elements[5*i+5].selectedIndex == 0) {
145: alert ("You must choose the answer format in True/False questions")
146: return false
147: }
148: }
149: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "Ord") {
150: if (poolForm.elements[5*i+4].selectedIndex == 0) {
151: alert ("You must choose the foil labelling format in Ranking/ordering questions")
152: return false
153: }
154: if (poolForm.elements[5*i+5].selectedIndex == 0) {
155: alert ("You must choose the answer format in Ranking/ordering questions")
156: return false
157: }
158: }
159: if (poolForm.elements[5*i+3].options[poolForm.elements[5*i+3].selectedIndex].value == "-1") {
160: alert ("You must choose the question type for block "+iter)
161: return false
162: }
163: if ((poolForm.elements[5*i+1].value == "") || !(poolForm.elements[5*i+1].value)) {
164: alert ("You must choose the start number for block "+iter)
165: return false
166: }
167: if ((poolForm.elements[5*i+2].value == "") || !(poolForm.elements[5*i+2].value)) {
168: alert ("You must choose the end number for block "+iter)
169: return false
170: }
171: if (poolForm.elements[5*i+2].value - poolForm.elements[5*i+1].value < 0) {
172: alert ("In block: "+iter+" the end number must be the same or greater than the start number")
173: return false
174: }
175: if (i == 0) {
176: curmin = parseInt(poolForm.elements[5*i+1].value)
177: curmax = parseInt(poolForm.elements[5*i+2].value)
178: }
179: else {
180: if (parseInt(poolForm.elements[5*i+1].value) < curmin) {
181: if (parseInt(poolForm.elements[5*i+2].value) >= curmin ) {
182: alert("The question number range for block "+iter+" overlaps with the question number range for one of the previous blocks - this is not permitted.")
183: return false
184: }
185: }
186: else {
187: if (parseInt(poolForm.elements[5*i+1].value) <= curmax) {
188: for (var j=parseInt(poolForm.elements[5*i+1].value); j<=parseInt(poolForm.elements[5*i+2].value); j++) {
189: for (var k=0; k<i; k++) {
190: if ((j >= parseInt(poolForm.elements[5*k+1].value)) && (j <= parseInt(poolForm.elements[5*k+2].value))) {
191: var overlap = k+1
192: alert("The question number range for block "+iter+" overlaps with the question number range for block "+overlap+" - this is not permitted.")
193: return false
194: }
195: }
196: }
197: }
198: }
199: if (parseInt(poolForm.elements[5*i+1].value) < curmin) {
200: curmin = parseInt(poolForm.elements[5*i+1].value)
201: }
202: if (parseInt(poolForm.elements[5*i+2].value) > curmax) {
203: curmax = parseInt(poolForm.elements[5*i+2].value)
204: }
205: }
206: }
207: if (curmax >$qcount+curmin) {
208: alert("The last # for one or more of the blocks is too large - the last number of the last block can not be greater than $qcount: the total number of questions in the uploaded file.")
209: return false
210: }
211: var endpt = $qcount + curmin
212: for (var n=curmin; n<endpt; n++) {
213: var warnFlag = true
214: for (var m=0; m<$blocks; m++) {
215: if ((n >= parseInt(poolForm.elements[5*m+1].value)) && (n <= parseInt(poolForm.elements[5*m+2].value))) {
216: warnFlag = false
217: }
218: }
219: if (warnFlag) {
220: alert("The question type for question "+n+" could not be identified because it does not fall within the number ranges you have provided for any of the $blocks block(s)")
221: return false
222: }
223: }
224: return true
225: }
226:
227: function nextPage() {
228: if (verify()) {
229: document.forms.display.go.value="NextPage"
230: document.forms.display.submit()
231: }
232: }
233: function backPage() {
234: document.forms.display.go.value="PreviousPage"
235: document.forms.display.submit()
236: }
237: function colSet(caller) {
238: var poolForm = document.forms.display
239: var curVal = poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value
240: poolForm.elements[caller*5+4].length = 0
241: if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "-1") {
242: poolForm.elements[caller*5+4].options[0] = new Option("<--- Set type ","-1",true,true)
243: }
244: else {
245: if ((poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "MC") || (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "MA") || (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "Ord")) {
246: poolForm.elements[caller*5+4].options[0] = new Option("Please Select","-1",true,true)
247: poolForm.elements[caller*5+4].options[1] = new Option("a.","lcperiod",false,false)
248: poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false)
249: poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false)
250: poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false)
1.5 raeburn 251: poolForm.elements[caller*5+4].options[5] = new Option("a)","lconeparen",false,false)
252: poolForm.elements[caller*5+4].options[6] = new Option("A)","uconeparen",false,false)
253: poolForm.elements[caller*5+4].options[7] = new Option("a.)","lcdotparen",false,false)
254: poolForm.elements[caller*5+4].options[8] = new Option("A.)","ucdotparen",false,false)
255: poolForm.elements[caller*5+4].options[9] = new Option("(i)","romparen",false,false)
256: poolForm.elements[caller*5+4].options[10] = new Option("i)","romoneparen",false,false)
257: poolForm.elements[caller*5+4].options[11] = new Option("i.)","romdotparen",false,false)
258: poolForm.elements[caller*5+4].options[12] = new Option("i.","romperiod",false,false)
1.1 raeburn 259: poolForm.elements[caller*5+4].selectedIndex = 0
260: }
261: else {
262: poolForm.elements[caller*5+4].options[0] = new Option("Not required","0",true,true)
263: }
264: }
265: poolForm.elements[caller*5+5].length = 0
266: if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "-1") {
267: poolForm.elements[caller*5+5].options[0] = new Option("<--- Set type ","-1",true,true)
268: }
269: else {
270: if ((poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "MA") || (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "FIB")) {
271: poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true)
272: poolForm.elements[caller*5+5].options[1] = new Option("single answer","single",false,false)
273: poolForm.elements[caller*5+5].options[2] = new Option("comma","comma",false,false)
274: poolForm.elements[caller*5+5].options[3] = new Option("space","space",false,false)
275: poolForm.elements[caller*5+5].options[4] = new Option("new line","line",false,false)
276: poolForm.elements[caller*5+5].options[5] = new Option("tab","tab",false,false)
277: }
278: else {
279: if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "Ord") {
280: poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true)
281: poolForm.elements[caller*5+5].options[1] = new Option("comma","comma",false,false)
282: poolForm.elements[caller*5+5].options[2] = new Option("space","space",false,false)
283: poolForm.elements[caller*5+5].options[3] = new Option("new line","line",false,false)
284: poolForm.elements[caller*5+5].options[4] = new Option("tab","tab",false,false)
285: }
286: else {
287: if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "TF") {
288: poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true)
289: poolForm.elements[caller*5+5].options[1] = new Option("True or False","word",false,false)
1.5 raeburn 290: poolForm.elements[caller*5+5].options[2] = new Option("true or false","word",false,false)
291: poolForm.elements[caller*5+5].options[3] = new Option("TRUE or FALSE","word",false,false)
292: poolForm.elements[caller*5+5].options[4] = new Option("T or F","lett",false,false)
293: poolForm.elements[caller*5+5].options[5] = new Option("t or f","lett",false,false)
1.1 raeburn 294: }
295: else {
296: poolForm.elements[caller*5+5].options[0] = new Option("Not required","0",true,true)
297: }
298: }
299: }
300: }
301: }
302:
303: function setElements() {
304: var iter = 0
305: var selParam = 0
306: END_SCRIPT
307: my @names = ("start_","end_","qtype_","foilformat_","ansr_");
308: for (my $x=0; $x<$blocks; $x++) {
309: foreach my $name (@names) {
310: my $parname = $name.$x;
1.6 albertel 311: my $value = $env{"form.$parname"};
1.1 raeburn 312: if ($value ne "") {
313: if (($name eq "start_") || ($name eq "end_")) {
314: $$jsref .= qq|
315: document.forms.display.$parname.value = $value\n|;
316: } elsif ($name eq "qtype_") {
317: $$jsref .= qq|
318: for (iter=0; iter<document.forms.display.$parname.length; iter++) {
319: if (document.forms.display.$parname.options[iter].value == "$value") {
320: selParam = iter
321: }
322: }
323: document.forms.display.$parname.selectedIndex = selParam
324: colSet($x)
325: |;
326: } elsif (($name eq "foilformat_") || ($name eq "ansr_")) {
327: $$jsref .= <<"TO_HERE";
328: for (iter=0; iter<document.forms.display.$parname.length; iter++) {
329: if (document.forms.display.$parname.options[iter].value == "$value") {
330: selParam = iter
331: }
332: }
333: document.forms.display.$parname.selectedIndex = selParam
334: TO_HERE
335: }
336: }
337: }
338: }
339: $$jsref .= qq|
340: }
341: |;
342: }
343: # ---------------------------------------------------------------- Jscript Three
344:
345: sub jscript_three {
346: my ($fullpath,$jsref) = @_;
347: my $source = '';
1.6 albertel 348: if (exists($env{'form.go'}) ) {
349: $source = $env{'form.go'};
1.1 raeburn 350: }
1.8 albertel 351:
1.10 albertel 352: my %body_layout = ('rightmargin' => "0",
353: 'leftmargin' => "0",
354: 'marginwidth' => "0",
355: 'topmargin' => "0",
356: 'marginheight' => "0");
357:
1.8 albertel 358: my $start_page =
1.9 albertel 359: &Apache::loncommon::start_page('Create Testbank directory',undef,
1.8 albertel 360: {'only_body' => 1,
1.10 albertel 361: 'add_entries' => \%body_layout,
1.8 albertel 362: 'js_ready' => 1,});
363: my $end_page =
364: &Apache::loncommon::end_page({'js_ready' => 1,});
1.1 raeburn 365: $$jsref = <<"END_OF_ONE";
366: function verify() {
367: if ((document.forms.dataForm.newdir.value == '') || (!document.forms.dataForm.newdir.value)) {
368: alert("Step 4: You must choose a destination directory for the import")
369: return false
370: }
371: return true
372: }
373:
374: function nextPage() {
375: if (verify()) {
376: document.forms.dataForm.go.value="NextPage"
377: document.forms.dataForm.submit()
378: }
379: }
380: function backPage() {
381: document.forms.dataForm.go.value="PreviousPage"
382: document.forms.dataForm.submit()
383: }
384:
385: function createWin() {
386: document.dataForm.newdir.value = "";
387: newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
388: newWindow.document.open()
1.8 albertel 389: newWindow.document.write('$start_page')
1.1 raeburn 390: newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")
391: newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='430' bgcolor='#CCFFDD'>\\n")
392: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
393: newWindow.document.write("<td><h3>Location: <tt>$fullpath</tt></h3><h3>New Directory</h3></td></tr>\\n")
394: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
395: newWindow.document.write("<td><form name='fileaction' action='/adm/cfile' method='post'>\\n")
1.12 albertel 396: newWindow.document.write("<font face='arial,helvetica,sans-serif'>Enter the name of the new directory where you will save the converted testbank questions<br /><br />")
1.1 raeburn 397: newWindow.document.write("<input type='hidden' name='filename' value='$fullpath'>")
398: newWindow.document.write("<input type='hidden' name='action' value='newdir'>")
399: newWindow.document.write("<input type='hidden' name='callingmode' value='testbank'>")
400: newWindow.document.write("$fullpath<input type='text' name='newfilename' value=''/>")
401: newWindow.document.write("<input type='button' value='Go' onClick='document.fileaction.submit();' />")
402: newWindow.document.write("</td></tr>\\n")
1.8 albertel 403: newWindow.document.write("</table>")
404: newWindow.document.write('$end_page')
1.1 raeburn 405: newWindow.document.close()
406: newWindow.focus()
407: }
408: END_OF_ONE
409: if ($source eq "PreviousPage") {
410: $$jsref .= qq|
411: function setElements() {
412: var iter = 0
413: var selParam = 0
414: |;
1.6 albertel 415: foreach my $item (keys %env) {
1.1 raeburn 416: if ($item =~ m/^form\.(\w+)$/) {
417: my $name = $1;
1.6 albertel 418: my $value = $env{"form.$name"};
1.1 raeburn 419: unless ($value eq "") {
420: if ($name eq "newdir") {
421: $$jsref .= qq( document.forms.dataForm.$name.value = "$value"\n);
422: }
423: }
424: }
425: }
426: $$jsref .= "}";
427: }
428: }
429:
430:
431: # ---------------------------------------------------------------- Jscript Four
432: sub jscript_four {
433: my ($jsref,$fullpath) = @_;
434: $$jsref = qq|
435: function backtoStart() {
436: document.location.href="$fullpath"
437: }
438: function backpage() {
439: document.forms.verify.go.value="PreviousPage"
440: document.forms.verify.submit()
441: }
442: |;
443: }
444:
445: # ---------------------------------------------------------------- Display Zero
446: sub display_zero {
447: my ($r,$uname,$fn,$page,$fullpath) = @_;
448: $r->print(qq|
449: <table border='0' cellspacing='0' cellpadding='0' width='100%'>
450: <tr>
451: <td> </td>
452: <td colspan='2'><font face='arial,helvetica,sans-serif'>
453: The <b>Testbank Upload</b> utility can be used by LON-CAPA authors to convert <i>multiple choice</i>, <i>multiple answer correct</i>, <i>fill-in-the-blank</i>, <i>ordering/ranking</i>, <i>true/false</i> and <i>essay</i> questions from a plain text testbank file to LON-CAPA problem files. Five requirements must be met to ensure that you will succeed in converting your plain text file of testbank questions to functioning LON-CAPA problems.
454: <ol>
455: <li>The questions and answers you upload must be in plain text format. Any header lines should occur before the text containing the questions and answers.</li>
456: <li>All questions (including question text and all foils) must occur before any of the answers. Each question should begin on a new line, and should start with the question number. Questions should be numbered sequentially using a number followed immediately by a space, a period, or enclosed in parentheses, i.e., 1 , 1., (1), 1), or (1 .</li>
457: <li><i>Multiple choice</i> and <i>multiple answer correct</i> questions should consist of: (i) the question number followed by (ii) the question text beginning on the same line and (iii) two or more foils, with each foil beginning on a new line and prefixed by a unique letter, or Roman numeral, listed in alphabetic or numeric order, beginning at a (alphabetic) or i (Roman numeral), followed by a period, or enclosed in parentheses, i.e., a., (a), i., or (i).</li>
458: <li>One or more correct answers should be provided for all questions (although blank answers may be provided for <i>essay</i> questions). Answers should be numbered sequentially, using the same scheme as used for the questions, and must occur after <b>all</b> the questions.
1.14 ! raeburn 459: <li>If <i>fill-in-the-blank</i> or <i>multiple answer</i> questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list. For a <i>ranking/ordering</i> question, the "answer" should contain the foil identifiers correctly ordered in a similarly delimited list. If two or more foils have the same ranking, they should occur together, with an equals sign separating equally ranked foils [e.g., (b),(e)=(a),(d),(c)].</li>
! 460: </ol>
1.1 raeburn 461: Five steps are involved in the import process.
462: <ol>
463: <li>Upload your text file to the server.|);
464:
465: if ($fn eq '') {
466: $r->print("<b>Incomplete</b>. Please return to the <a href='$fullpath'>construction space menu<a> to upload a file");
467: } else {
468: $r->print(" <b>Completed</b> - successful upload of <i>$fn</i>");
469: }
470: $r->print(qq|</li>
471: <li>Provide information about the question format - i.e., question numbering style, and the number of blocks of questions of each question type.</li>
472: <li>Provide information about the questions in each block, including question type, start and end question numbers for each block, and foil labelling style and answer format where required.</li>
1.12 albertel 473: <li>Create a new directory where you will save the converted testbank questions.</li>
1.1 raeburn 474: <li>Complete the import of questions to the selected pool.</li>
475: </ol>
476: </font>
477: </td>
478: </tr>
479: </table>
480: <br />
481: <br />
482: <form name="info" method="post">
483: <input type="hidden" name="uploaduname" value="$uname">
484: <input type="hidden" name="filename" value="$fn">
485: <input type="hidden" name="page" value="$page">
486: <input type="hidden" name="phase" value="three">
487: <input type="hidden" name="go" value="NextPage">
488: <table border="0" width="100%">
489: <tr>
490: <td align='left'>
491: <input type="button" name="goback" value="Exit Now" onClick="javascript:location.href='$fullpath'">
492: </td>
493: <td align='right'>
494: <input type="button" name="nextpage" value="Continue to step 2" onClick="javascript:submit()">
495: </td>
496: </tr>
497: </table>
498: </form>
499: |);
500: }
501:
502:
503: # ---------------------------------------------------------------- Display One
504:
505: sub display_one {
506: my ($r,$uname,$fn,$page,$textref) = @_;
507: $r->print(qq|
508: <form method='post' name='display'>
509: <table border='0' cellspacing='0' cellpadding='3' width='100%'>
510: <tr bgcolor='#ccddaa'>
511: <td> </td>
512: <td align='left'>
513: <h3><font face='arial,helvetica,sans-serif'>Step 2: Identification of blocks of questions</b> </font></h3>
514: </td>
515: </tr>
516: <tr>
517: <td colspan='2'> </td>
518: </tr>
519: <tr>
520: <td colspan='2'>
521: <table border="0" cellspacing="0" cellpadding="2">
522: <tr>
523: <td> </td>
524: <td colspan='2'>
525: <font face='arial,helvetica,sans-serif'><b>Testbank data uploaded to the server:</b></font>
526: </td>
527: </tr>
528: <tr>
529: <td colspan='3'> </td>
530: </tr>
531: <tr>
532: <td> </td>
533: <td colspan='2'>
534: <textarea name="rawdata" cols="70" rows="6" wrap="virtual" align="center">
535: |);
536: foreach my $line (@{$textref}) {
537: $line =~ s/\n//g;
538: $r->print("$line\n");
539: }
540: $r->print(qq|
541: </textarea>
542: </td>
543: </tr>
544: <tr>
545: <td colspan='3'> </td>
546: </tr>
547: <tr>
548: <tr>
549: <td colspan='3'> </td>
550: </tr>
551: <tr bgcolor='#ccddaa'>
552: <td> </td>
553: <td align='left' valign='middle'><img src="/res/adm/pages/bl_step1.gif">
554: </td>
555: <td>
556: <font face='arial,helvetica,sans-serif'><b>
557: Select the format of the question number</b> [e.g., 1, 1., 1), (1 or (1)].
558: <select name="qnumformat">
559: <option value = "-1" selected>Please Select
560: <option value="number">1
561: <option value="period">1.
562: <option value="paren">(1)
563: <option value="leadparen">(1
564: <option value="trailparen">1)
565: </select>
566: </font>
567: </td>
568: </tr>
569: <tr>
570: <td colspan='3'> </td>
571: </tr>
572: <tr>
573: <td> </td>
574: <td colspan='2'><font face='arial,helvetica,sans-serif'>
575: A number in the specified format should appear at the start of each question. For multiple choice questions, the question number must begin the line that contains the question text; foils (starting (a), (i) etc.) should occur on subsequent lines. Correct answers should be numbered in the same way as the questions and should appear after <b>all</b> the questions (including question text and possible foils for all questions). Each numbered question must have a corresponding numbered answer, although the answer itself may be blank for essay questions.</td>
576: </tr>
577: <tr>
578: <td colspan="3"> </td>
579: </tr>
580: <tr>
581: <td> </td>
582: <td colspan='2'>
583: <font face='arial,helvetica,sans-serif'>
584: For example, you would select <b>1.</b> if your text file contained the following questions:<br><br>
585: 1. The capital of the USA is ..<br />
586: (a) Washington D.C.<br />
587: (b) New York<br />
588: (c) Los Angeles<br />
589: <br />
590: 2. The capital of Canada is ..<br />
591: (a) Toronto<br />
592: (b) Vancouver<br />
593: (c) Ottawa<br />
594: <br />
595: 3. Describe an experiment you could conduct to measure c, the speed of light in a vacuum. <br /><br />
596: 1. (a)<br />
597: 2. (c)<br />
598: 3. <br />
599: </td>
600: <tr>
601: <td colspan="3"> </td>
602: </tr>
603: <tr bgcolor='#ccddaa'>
604: <td> </td>
605: <td><img src='/res/adm/pages/bl_step2.gif' align='left' valign='middle'>
606: </td>
607: <td>
608: <font face='arial,helvetica,sans-serif'><b>
609: Please indicate the number of blocks of different question types in the text file.</b>
610: <input type="text" name="blocks" value="" size="5">
611: </td>
612: </tr>
613: <tr>
614: <td colspan="3"> </td>
615: </tr>
616: <tr>
617: <td> </td>
618: <td colspan='2'>
619: <font face='arial,helvetica,sans-serif'>
620: For example, you would enter <b>6</b> if your text file contained the following sequence of questions:<br><br>
621: 10 multiple choice questions<br>
622: 5 essay questions<br>
623: 5 fill-in-the-blank questions<br>
624: 5 multiple answer questions<br>
625: 4 multiple choice questions<br>
626: 3 essay questions<br>
627: </font>
628: </td>
629: </tr>
630: <tr>
631: <td colspan='3'> </td>
632: </tr>
633: <tr>
634: <td> </td>
635: <td colspan='2'><font face='arial,helvetica,sans-serif'>You will indicate the question type and the question number range for each of the blocks on the next page.</font></td>
636: </tr>
637: <tr>
638: <td colspan='3'> </td>
639: </tr>
640: <tr>
641: <td colspan='3'>
642: <table border='0' width="100%" cellspacing='0' cellpadding='2'>
643: <tr>
644: <td align='left'>
645: <input type="button" name="backpage" value="Go back to step 1" onClick="javascript:backPage()">
646: </td>
647: <td align='right'>
648: <input type="button" name="nextpage" value="Continue to step 3" onClick="javascript:nextPage()">
649: </td>
650: </tr>
651: </table>
652: <input type="hidden" name="page" value ="$page">
653: <input type="hidden" name="go" value="">
654: <input type="hidden" name="uploaduname" value="$uname">
655: <input type="hidden" name="filename" value="$fn">
656: <input type="hidden" name="phase" value="three">
657: </td>
658: </tr>
659: </table>
660: </td>
661: </tr>
662: </table>
663: </form>
664: |);
665: }
666:
667: # ---------------------------------------------------------------- Display Two
668:
669: sub display_two {
670: my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
1.6 albertel 671: my $blocks = $env{'form.blocks'};
672: my $qnumformat = $env{'form.qnumformat'};
1.1 raeburn 673: my @types = ("MC","MA","TF","Ess","FIB","Ord");
674: my %typenames = (
675: MC => "Multiple Choice",
676: TF => "True/False",
677: MA => "Multiple Answer",
678: Ess => "Essay",
679: FIB => "Fill-in-the-blank",
680: Ord => "Ranking/ordering",
681: );
682: my %qnumtypes = (
683: number => "1",
684: period => "1.",
685: paren => "(1)",
686: leadparen => "(1",
687: trailparen => "1)",
688: );
689: my @bgcolors = ('#ffffff','#eeeeee');
690: my $bl1st = '';
691: my $bl1end = '';
692: if ($blocks == 1) {
693: $bl1st = '1';
694: $bl1end = $qcount;
695: }
696: $r->print(<<"END_OF_FUNC");
697: <h3><font face='arial,helvetica,sans-serif'>Step 3: Classification of blocks</b> </font></h3>
698: <form method='post' name='display'>
699: <table border='0' cellspacing='0' cellpadding ='0'>
700: <tr>
701: <td colspan='2'> </td>
702: </tr>
703: <tr>
704: <td colspan='2'>
705: <table border="0" cellspacing="0" cellpadding="0">
706: <tr>
707: <td> </td>
708: <td><font face='arial,helvetica,sans-serif'>
709: You indicated that <b>all</b> questions (and the corresponding answer(s) for each question) begin with a number in the following format: <b>$qnumtypes{$qnumformat}</b>.<br><br>A total of <b>$qcount</b> questions and <b>$qcount</b> corresponding answers were found in the file you uploaded. If this questions total does not match the number you expect, please examine your original text file to verify that each question <i>and</i> each answer begins with a number in the specified format. If necessary use a text editor to edit your text file of questions, and click "Return to step 2" on this page and the "Return to Step 1" on the preceding page, so you can upload your text file again.<br><br>
710: You also indicated that the <b>$qcount</b> questions can be divided into <b>$blocks</b> blocks of questions of a particular question type.</font>
711: </td>
712: </tr>
713: <tr>
714: <td colpsan='2'> </td>
715: </tr>
716: <tr>
717: <td> </td>
718: <td><font face='arial,helvetica,sans-serif'>
719: Please provide additional information below ,about the types of questions you have uploaded, and, if applicable, the format of answers and "foils" for specific types of questions.
720: </td>
721: </tr>
722: <tr>
723: <td colpsan='2'> </td>
724: </tr>
725: <tr>
726: <td> </td>
727: <td>
728: <font face='arial,helvetica,sans-serif'>The following data were uploaded to the server</font><br>
729: <textarea name="rawdata" cols="70" rows="6" wrap="virtual" align="center">
730: END_OF_FUNC
731: foreach my $line (@{$textref}) {
732: $line =~ s/\n//g;
733: $r->print("$line\n");
734: }
735: $r->print(qq|
736: </textarea>
737: </td>
738: </tr>
739: <tr>
740: <td colspan='2'> </td>
741: </tr>
742: <tr bgcolor='#ccddaa'>
743: <td><img src='/res/adm/pages/bl_step3.gif' align='left' valign='middle'>
744: </td>
745: <td width='100%' align='left'>
746: <font size='+1' face='arial,helvetica,sans-serif'><b>Information about question types and formats in each block.</b></font>
747: </td>
748: </tr>
749: <tr>
750: <td colspan='2'> </td>
751: </tr>
752: <tr>
753: <td> </td>
754: <td><font face='arial,helvetica,sans-serif'>For <i>each</i> of the <b>$blocks</b> question blocks, please specify the question numbers of the first and last questions in the block (e.g., 1 and 10), and the question type of the questions in the block. Please provide additional information about foil formats and answer formats if required for the question type you selected.</font>
755: </td>
756: </tr>
757: <tr>
758: <td colspan='2'> </td>
759: </tr>
760: <tr>
761: <td> </td>
762: <td>
763: <table border="0" cellspacing="0" cellpadding="0" bgcolor="#000000" align="left">
764: <tr>
765: <td>
766: <table border="1" valign="top" align="center" width='100%'>
767: <tr bgcolor="#eef6f6" align="left">
768: <td>
769: <table border='0' cellspacing='1' cellpadding='1' align='left' width='100%'>
770: <tr bgcolor='#CCDDAA' align='center' valign='middle'>
771: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
772: <b>Block</b> </font>
773: </td>
774: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
775: <b>First number</b> </font>
776: </td>
777: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
778: <b>Last number</b> </font>
779: </td>
780: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
781: <b>Question type</b> </font>
782: </td>
783: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
784: <b>Foil format</b> </font>
785: </td>
786: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
787: <b>Answer format</b> </font>
788: </td>
789: </tr>
790: |);
791: for (my $i=0; $i<$blocks; $i++) {
792: my $iter = $i+1;
793: my $rowcol = $i%2;
794: $r->print(qq|
795: <tr bgcolor="$bgcolors[$rowcol]">
796: <td align="left">
797: <font face='arial,helvetica,sans-serif'> $iter.</font>
798: </td>
799: <td align="left">
800: <input type="text" name="start_$i" value="$bl1st" size="5">
801: </td>
802: <td align="left">
803: <input type="text" name="end_$i" value="$bl1end" size="5">
804: </td>
805: <td align="left">
806: <font face='arial,helvetica,sans-serif'>
807: <select name="qtype_$i" onChange="colSet($i)">
808: <option value= "-1" selected>Please Select
809: |);
810: foreach my $qtype (@types) {
811: $r->print(qq|<option value="$qtype">$typenames{$qtype}|);
812: }
813: $r->print(qq|
814: </select>
815: </font>
816: </td>
817: <td align="left">
818: <select name="foilformat_$i">
819: <option value="-1"><--- Set type
820: </select>
821: </td>
822: <td align="left">
823: <select name="ansr_$i">
824: <option value="-1"><--- Set type
825: </select>
826: </td>
827: </tr>
828: |);
829: }
830: $r->print(qq|
831: </table>
832: </td>
833: </tr>
834: </table>
835: </td>
836: </tr>
837: </table>
838: </td>
839: </tr>
840: <tr>
841: <td colspan="2"> </td>
842: </tr>
843: <tr>
844: <td> </td>
845: <td>
846: <font face='arial,helvetica,sans-serif'>For <i>multiple choice</i>, <i>multiple correct answer</i> and <i>ranking</i> type questions, you must use the <b>Foil format</b> column to choose the format of the identifier used for each of the possible answers (e.g., (a), a, a., i, (i) etc.) provided for a given question stem. For <i>multiple correct answer</i> and <i>fill-in-the-blank</i> questions with more than one correct answer you must use the <b>Answer format</b> column to choose the separator used between the answers, e.g., if the correct answers for question 28. were listed as: 28. (a),(d),(e) you would choose "comma", or if they were listed as:</font><br><table border='0'><tr><td><font face='arial,helvetica,sans-serif'>28. </font></td><td><font face='arial,helvetica,sans-serif'>(a)</font></td></tr><tr><td> </td><td><font face='arial,helvetica,sans-serif'>(d)</font></td></tr><tr><td> </td><td><font face='arial,helvetica,sans-serif'>(e)</font></td></tr></table>
847: <font face='arial,helvetica,sans-serif'>you would choose "new line". For <i>true/false</i> questions you must use the <b>Answer format</b> column to choose how the correct answer - True or False, is displayed in the text file (e.g., T or F, true or false etc.). For <i>ranking</i> questions you must use the <b>Answer format</b> column to choose the separator used between the (ranked) answers.</font><br><br>
848: </td>
849: </tr>
850: <tr>
851: <td colspan='2'> </td>
852: </tr>
853: <tr>
854: <td colspan='2'>
855: <input type="hidden" name="blocks" value="$blocks">
856: <input type="hidden" name="qnumformat" value="$qnumformat">
857: <table border='0' width="100%" cellspacing='0' cellpadding='2'>
858: <tr>
859: <td align='left'>
860: <input type="button" name="backpage" value="Go back to step 2" onClick="javascript:backPage()">
861: </td>
862: <td align='right'>
863: <input type="button" name="nextpage" value="Continue to step 4" onClick="javascript:nextPage()">
864: </td>
865: </tr>
866: </table>
867: <input type="hidden" name="page" value ="$page">
868: <input type="hidden" name="go" value="">
869: <input type="hidden" name="uploaduname" value="$uname">
870: <input type="hidden" name="filename" value="$fn">
871: <input type="hidden" name="phase" value="three">
872: </form>
873: </td>
874: </tr>
875: </table>
876: </td>
877: </tr>
878: </table>
879: |);
880: }
881: # ---------------------------------------------------------------- Display Three
882: sub display_three {
883: my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
1.6 albertel 884: my $qnumformat = $env{'form.qnumformat'};
885: my $filename = $env{'form.filename'};
886: my $source = $env{'form.go'};
887: my $blocks = $env{'form.blocks'};
1.1 raeburn 888: my @items = ();
889: my @bgcolors = ('#ffffff','#eeeeee');
890: my @types = ("MC","MA","TF","Ess","FIB","Ord");
891: my @alphabet = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
892: my @romans = ("i","ii","iii","iv","v","vi","vii","viii","ix","x","xi","xii","xiii","xiv","xv","xvi","xvii","xviii","xix","xx","xxi","xxii","xxiii","xxiv","xxv","xxvi");
893: my @start = ();
894: my @end = ();
895: my @nums = ();
896: my @qtype = ();
897: my @foilformats = ();
898: my @ansrtypes = ();
899: my %multparts = ();
900: my $numitems = 0;
901: for (my $i=0; $i<$blocks; $i++) {
1.6 albertel 902: if (($env{"form.start_$i"} ne '') && ($env{"form.end_$i"} ne '')) {
903: $start[$i] = $env{"form.start_$i"};
904: $end[$i] = $env{"form.end_$i"};
1.1 raeburn 905: $nums[$i] = $end[$i]-$start[$i] +1;
1.6 albertel 906: $qtype[$i] = $env{"form.qtype_$i"};
1.1 raeburn 907: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.6 albertel 908: $foilformats[$i] = $env{"form.foilformat_$i"};
1.1 raeburn 909: } else {
910: $foilformats[$i] = '';
911: }
912: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1.6 albertel 913: $ansrtypes[$i] = $env{"form.ansr_$i"};
1.1 raeburn 914: } else {
915: $ansrtypes[$i] = '';
916: }
917: } else {
918: $nums[$i] = 0;
919: }
920: $numitems += $nums[$i];
921: }
922:
923: my $import = join//,@{$textref};
924: @items = &file_split(\@start,\@end,\@nums,$qnumformat,\@foilformats,$textref,\%multparts,$numitems,\@qtype,$blocks);
925: $r->print(<<"END_OF_ONE");
926: <h3><font face='arial,helvetica,sans-serif'>Step 4: Review and selection of destination directory</b> </font></h3>
927: <form name="dataForm" method="post">
928: <table border='0' bgcolor='#CCFFDD' cellspacing='0' cellpadding ='0'>
929: <tr>
930: <td colspan='2'>
931: <table border='0' cellspacing='0' cellpadding='0'>
932: <tr>
933: <td colspan='2'> </td>
934: </tr>
935: <tr>
936: <td> </td>
937: <td><font face='arial,helvetica,sans-serif'><b>
938: Based on your previous responses your data have been split into a total of $numitems questions.</b>
939: </td>
940: </tr>
941: <tr>
942: <td colspan='2'> </td>
943: </tr>
944: <tr>
945: <td> </td>
946: <td width="80%" bgcolor="#000000" align="left">
947: <table width="100%" border="0" cellpadding="1" cellspacing="0">
948: <tr>
949: <td width="100%" bgcolor="#000000">
950: <table border="0" cellspacing="0" cellpadding="1" width="100%">
951: <tr>
952: <td width="100%" bgcolor="#000000">
953: <table border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff" width="100%">
954: <tr>
955: <td bgcolor="#CCFFDD" width="100%">
956: <table border='0' cellspacing='1' cellpadding='2' align='left' width= '100%'>
957: <tr><td bgcolor="#CCDDAA" align="center" width='3%'><font face='arial,helvetica,sans-serif'><b>#</b></font></td><td bgcolor="#CCDDAA" align="center" width='5%'><font face='arial,helvetica,sans-serif'><b>Type</b></font></td><td bgcolor="#CCDDAA" align="center" width='60%'><font face='arial,helvetica,sans-serif'><b>Question</b></font></td><td bgcolor="#CCDDAA" align="center" width='32%'><font face='arial,helvetica,sans-serif'><b>Answer</b></font></td></tr>
958: END_OF_ONE
959: for (my $j=0; $j<$numitems; $j++) {
960: my $qnum = $j+1;
961: my $rowcol = $j%2;
962: $rowcol = @bgcolors[$rowcol];
963: for (my $i=0; $i<$blocks; $i++) {
964: if ($nums[$i] > 0) {
965: if (($j+1 >= $start[$i]) && ($j+1 <= $end[$i])) {
966: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA")) {
967: for (my $k=0; $k<@{$multparts{$j}}; $k++) {
968: if ($k == 0) {
969: $r->print(qq|<tr><td bgcolor="$rowcol" valign='top'><font face='arial,helvetica,sans-serif'>$qnum.</font></td><td bgcolor="$rowcol" valign='top'><font face='arial,helvetica,sans-serif'><b>$qtype[$i]</b></font></td><td bgcolor="$rowcol" valign='top'><font face='arial,helvetica,sans-serif'>$multparts{$j}[$k]<br><br>\n|);
970: } else {
971: my $foiltag = '';
972: if ($foilformats[$i] eq "lcperiod") {
973: $foiltag = $alphabet[$k-1].'.';
974: } elsif ($foilformats[$i] eq "lcparen") {
975: $foiltag = '('.$alphabet[$k-1].')';
1.5 raeburn 976: } elsif ($foilformats[$i] eq "lconeparen") {
977: $foiltag = $alphabet[$k-1].')';
978: } elsif ($foilformats[$i] eq "lcdotparen") {
979: $foiltag = $alphabet[$k-1].'.)';
1.1 raeburn 980: } elsif ($foilformats[$i] eq "ucperiod") {
981: $foiltag = $alphabet[$k-1].'.';
982: $foiltag =~ tr/a-z/A-Z/;
983: } elsif ($foilformats[$i] eq "ucparen") {
984: $foiltag = '('.$alphabet[$k-1].')';
985: $foiltag =~ tr/a-z/A-Z/;
1.5 raeburn 986: } elsif ($foilformats[$i] eq "uconeparen") {
987: $foiltag = $alphabet[$k-1].')';
988: $foiltag =~ tr/a-z/A-Z/;
989: } elsif ($foilformats[$i] eq "ucdotparen") {
990: $foiltag = $alphabet[$k-1].'.)';
991: $foiltag =~ tr/a-z/A-Z/;
1.1 raeburn 992: } elsif ($foilformats[$i] eq "romperiod") {
993: $foiltag = $romans[$k-1].'.';
994: } elsif ($foilformats[$i] eq "romparen") {
995: $foiltag = '('.$romans[$k-1].')';
1.5 raeburn 996: } elsif ($foilformats[$i] eq "romoneparen") {
997: $foiltag = $romans[$k-1].')';
998: } elsif ($foilformats[$i] eq "romdotparen") {
999: $foiltag = $romans[$k-1].'.)';
1000: }
1.1 raeburn 1001: $r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|);
1002: }
1003: }
1004: $r->print(qq|<br></font></td><td bgcolor="$rowcol" valign='top'><font face='arial,helvetica,sans-serif'>$items[$j+$numitems]</font></td></tr>|);
1005: } else {
1006: $r->print(qq|<tr><td bgcolor="$rowcol" valign="top"><font face='arial,helvetica,sans-serif'>$qnum.</font></td><td bgcolor="$rowcol" valign="top"><font face='arial,helvetica,sans-serif'><b>$qtype[$i]</b></font></td><td bgcolor="$rowcol" valign="top"><font face='arial,helvetica,sans-serif'>$items[$j]</font></td><td bgcolor="$rowcol" valign="top"><font face='arial,helvetica,sans-serif'>$items[$j+$numitems]</font></td></tr>|);
1007: }
1008: last;
1009: }
1010: }
1011: }
1012: }
1013: $r->print(qq|
1014: </table>
1015: </td>
1016: </tr>
1017: </table>
1018: </td>
1019: </tr>
1020: </table>
1021: </td>
1022: </tr>
1023: </table>
1024: </td>
1025: </tr>
1026: <tr>
1027: <td colspan='2'> </td>
1028: </tr>
1029: <tr bgcolor='#ccddaa'>
1030: <td width='30' align='top'><img src='/res/adm/pages/bl_step4.gif'>
1031: </td>
1032: <td width='100%' align='left'>
1.12 albertel 1033: <font size='+1' face='arial,helvetica,sans-serif'><b>Create a directory to save your testbank questions.</b></font>
1.1 raeburn 1034: </td>
1035: </tr>
1036: <tr>
1037: <td colspan='2'> </td>
1038: </tr>
1039: <tr>
1040: <td> </td>
1041: <td>
1042: <font face='Arial,Helvetica,sans-serif'>
1.12 albertel 1043: Please choose a destination LON-CAPA directory in which to save your uploaded questions.
1.1 raeburn 1044: <input type="button" name="createdir" value="Create Directory" onClick="javascript:createWin()"><input type="hidden" name="newdir" value=""></font></td>
1045: </tr>
1046: <tr>
1047: <td colspan='2'> </td>
1048: </tr>
1049: <tr>
1050: <td> </td>
1051: <td><font face='arial,helvetica,sans-serif'>If you are satisfied with the questions and answers extracted from your uploaded text file, as shown above, and you have created a destination directory click the "Continue to step 5" button to convert the questions in your testbank to LON-CAPA problem files.</font></td>
1052: </tr>
1053: <tr>
1054: <td colspan='2'>
1055: <input type='hidden' name="go" value="">
1056: <input type='hidden' name="qnumformat" value="$qnumformat">
1057: <input type='hidden' name="blocks" value="$blocks">
1058: <input type="hidden" name="uploaduname" value="$uname">
1059: <input type="hidden" name="filename" value="$fn">
1060: <input type='hidden' name="page" value="$page">
1061: <input type="hidden" name="phase" value="three">
1062: |);
1063: for (my $i=0; $i<$blocks; $i++) {
1064: $r->print(qq|
1065: <input type='hidden' name="start_$i" value="$start[$i]">
1066: <input type='hidden' name="end_$i" value="$end[$i]">
1067: <input type='hidden' name="qtype_$i" value="$qtype[$i]">
1068: |);
1069: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1070: $r->print(qq|
1071: <input type='hidden' name="foilformat_$i" value="$foilformats[$i]">
1072: |);
1073: }
1074: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1075: $r->print(qq|
1076: <input type='hidden' name="ansr_$i" value="$ansrtypes[$i]">
1077: |);
1078: }
1079: }
1080: $r->print(qq|
1081: </td>
1082: </tr>
1083: <tr>
1084: <td colspan='2'> <br /><br /></td>
1085: </tr>
1086: <tr>
1087: <td colspan='2'>
1088: <table border='0' cellspacing='0' cellpadding='0' width="100%">
1089: <tr>
1090: <td align='left'>
1091: <input type="button" name="backpage" value="Go back to step 3" onClick="javascript:backPage()">
1092: </td>
1093: <td align='right'>
1094: <input type="button" name="nextpage" value="Continue to step 5" onClick="javascript:nextPage()">
1095: </td>
1096: </tr>
1097: </table>
1098: </td>
1099: </tr>
1100: </table>
1101: </td>
1102: </tr>
1103: </table>
1104: </form>
1105: |);
1106: }
1107:
1108: # ---------------------------------------------------------------- Final Display
1109: sub final_display {
1110: my ($r,$uname,$fn,$page,$textref) = @_;
1.6 albertel 1111: my $qnumformat = $env{'form.qnumformat'};
1112: my $blocks = $env{'form.blocks'};
1113: my $newdir = $env{'form.newdir'};
1.1 raeburn 1114: my $linkdir = $newdir;
1115: if ($linkdir =~ m#^/home/$uname/public_html/(.+)$#) {
1116: $linkdir = '/priv/'.$uname.'/'.$1;
1117: }
1118: my $question_id = '';
1119: my @question_title = ();
1120: my @question_status = ();
1121: my @qtype = ();
1122: my @start = ();
1123: my @nums = ();
1124: my @end = ();
1125: my @foilformats = ();
1126: my @ansrtypes = ();
1127: my %multparts = ();
1128: my $numitems = 0;
1129: for (my $i=0; $i<$blocks; $i++) {
1.6 albertel 1130: $start[$i] = $env{"form.start_$i"};
1131: $end[$i] = $env{"form.end_$i"};
1.1 raeburn 1132: if (($end[$i] - $start[$i]) >= 0) {
1133: $nums[$i] = $end[$i] - $start[$i]+1;
1134: } else {
1135: $nums[$i] = 0;
1136: }
1.6 albertel 1137: $qtype[$i] = $env{"form.qtype_$i"};
1.1 raeburn 1138: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.6 albertel 1139: $foilformats[$i] = $env{"form.foilformat_$i"};
1.1 raeburn 1140: } else {
1141: $foilformats[$i] = '';
1142: }
1143: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1.6 albertel 1144: $ansrtypes[$i] = $env{"form.ansr_$i"};
1.1 raeburn 1145: }
1146: $numitems += $nums[$i];
1147: }
1148:
1149: my @bgcolors = ('#ffffff','#eeeeee');
1150:
1151: my $import = join/'\s'/,@{$textref};
1152: my %answers = ();
1153: my @items = &file_split(\@start,\@end,\@nums,$qnumformat,\@foilformats,$textref,\%multparts,$numitems,\@qtype,$blocks);
1154:
1155: # Converting MC and MA answer to number, and splitting answers for FIB, and ordering for Ord.
1156: my @alphabet = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
1157: my @romans = ("i","ii","iii","iv","v","vi","vii","viii","ix","x","xi","xii","xiii","xiv","xv","xvi","xvii","xviii","xix","xx","xxi","xxii","xxiii","xxiv","xxv","xxvi");
1158: my %patterns = (
1159: comma => ',',
1160: space => '\s+',
1161: line => '[\r\n\f]+',
1162: tab => '\t+',
1163: );
1164: for (my $i=0; $i<$blocks; $i++) {
1165: if ($nums[$i] > 0) {
1166: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "Ord")) {
1167: for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) {
1168: @{$answers{$k}} = ();
1169: if ($qtype[$i] eq "MC") {
1.4 raeburn 1170: $items[$k] =~ tr/A-Z/a-z/;
1.1 raeburn 1171: $items[$k] =~ s/\W//g;
1.5 raeburn 1172: if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "lconeparen" || $foilformats[$i] eq "lcdotparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod" || $foilformats[$i] eq "uconeparen" || $foilformats[$i] eq "ucdotparen") {
1.1 raeburn 1173: for (my $j=0; $j<@alphabet; $j++) {
1174: if ($alphabet[$j] eq $items[$k]) {
1175: push @{$answers{$k}}, $j;
1176: last;
1177: }
1178: }
1.5 raeburn 1179: } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
1.1 raeburn 1180: for (my $j=0; $j<@romans; $j++) {
1181: if ($romans[$j] eq $items[$k]) {
1182: push @{$answers{$k}}, $j;
1183: last;
1184: }
1185: }
1186: }
1187: } elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.4 raeburn 1188: $items[$k] =~ tr/A-Z/a-z/;
1.1 raeburn 1189: my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k];
1190: foreach my $correct (@corrects) {
1.14 ! raeburn 1191: my @tied;
! 1192: if ($qtype[$i] eq "Ord") {
! 1193: if ($correct =~ /=/) {
! 1194: @tied = split(/=/,$correct);
! 1195: for (my $j=0; $j<@tied; $j++) {
! 1196: $tied[$j] =~ s/\W//g;
! 1197: }
! 1198: } else {
! 1199: $correct =~s/\W//g;
! 1200: }
! 1201: } else {
! 1202: $correct =~s/\W//g;
! 1203: }
1.1 raeburn 1204: if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {
1.14 ! raeburn 1205: if (($qtype[$i] eq "Ord") && (@tied > 0)) {
! 1206: my @ties;
! 1207: foreach my $tie (@tied) {
! 1208: for (my $j=0; $j<@alphabet; $j++) {
! 1209: if ($alphabet[$j] eq $tie) {
! 1210: push(@ties,$j);
! 1211: last;
! 1212: }
! 1213: }
! 1214: }
! 1215: my $ans = join('=',@ties);
! 1216: push(@{$answers{$k}},$ans);
! 1217: } else {
! 1218: for (my $j=0; $j<@alphabet; $j++) {
! 1219: if ($alphabet[$j] eq $correct) {
! 1220: push @{$answers{$k}}, $j;
! 1221: last;
! 1222: }
1.1 raeburn 1223: }
1224: }
1.5 raeburn 1225: } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
1.14 ! raeburn 1226: if (($qtype[$i] eq "Ord") && (@tied > 0)) {
! 1227: my @ties;
! 1228: foreach my $tie (@tied) {
! 1229: for (my $j=0; $j<@romans; $j++) {
! 1230: if ($romans[$j] eq $tie) {
! 1231: push(@ties,$j);
! 1232: last;
! 1233: }
! 1234: }
! 1235: }
! 1236: push(@{$answers{$k}},join('=',@ties));
! 1237: } else {
! 1238: for (my $j=0; $j<@romans; $j++) {
! 1239: if ($romans[$j] eq $correct) {
! 1240: push @{$answers{$k}}, $j;
! 1241: last;
! 1242: }
1.1 raeburn 1243: }
1244: }
1245: }
1246: }
1247: } elsif ($qtype[$i] eq "FIB") {
1248: @{$answers{$k}} = split/$patterns{$ansrtypes[$i]}/,$items[$k];
1249: for (my $j=0; $j<@{$answers{$k}}; $j++) {
1250: $answers{$k}[$j] =~ s/^\s+//;
1251: $answers{$k}[$j] =~ s/\s+$//;
1252: }
1253: }
1254: }
1255: }
1256: }
1257: }
1258: my $pooltarget = '';
1259: my $pooldesc = '';
1260: my @newquestions = ();
1261: my $numquestions = 0;
1262: my %qtype = ();
1263: my %qtext = ();
1264: my %qflag = ();
1265:
1266: $r->print(<<"END_OF_BLOCK");
1267: <form name="verify" method="post">
1268: <table border='0' cellspacing='0' cellpadding='0' width="100%">
1269: <tr>
1270: <td colspan='2' align='left'>
1271: </td>
1272: </tr>
1273: <tr bgcolor='#ccddaa'>
1274: <td align='top'>
1275: </td>
1276: <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
1277: <font size='+1' face='arial,helvetica,sans-serif'> <b>Result of conversion of tesbank questions to LON-CAPA problems.</b></font>
1278: </td>
1279: </tr>
1280: <tr>
1281: <td colspan='2'> </td>
1282: </tr>
1283: END_OF_BLOCK
1284: if ($newdir ne "") {
1285: my @qn_file = ();
1286: my $qcount = 0;
1287: for (my $i=0; $i<$blocks; $i++) {
1288: if ($nums[$i] > 0) {
1289: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "Ord")) {
1290: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1291: my $answer = $j + $numitems;
1292: my $numans = scalar(@{$answers{$answer}});
1293: my $foilcount = 0;
1294: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1295: $foilcount = @{$multparts{$j}};
1296: $foilcount --;
1297: }
1298: $qn_file[$qcount] = &create_mcq($newdir,\@{$multparts{$j}},\@{$answers{$answer}},$qtype[$i],$j);
1299: $qcount ++;
1300: push @newquestions, $question_id;
1301: }
1302: } elsif ($qtype[$i] eq "TF") {
1303: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1304: my $answer = $j + $numitems;
1305: $items[$answer] =~ s/^\s+//;
1306: $items[$answer] =~ s/\s+$//;
1307: $items[$answer] =~ s/\W//g;
1308: $items[$answer] =~ tr/A-Z/a-z/;
1309: my $answer_id = '';
1310: if ($ansrtypes[$i] eq 'word' ) {
1311: if ($items[$answer] =~ m/true/) {
1312: $answer_id = 0;
1313: } else {
1314: $answer_id = 1;
1315: }
1316: } elsif ($ansrtypes[$i] eq 'lett') {
1317: if ($items[$answer] =~ m/^t/) {
1318: $answer_id = 0;
1319: } else {
1320: $answer_id = 1;
1321: }
1322: }
1323: $qn_file[$qcount] = create_ess($newdir,$answer_id,$items[$j],$items[$answer],$qtype[$i],$j);
1324: push @newquestions, $question_id;
1325: $qcount ++;
1326: }
1327: } elsif ($qtype[$i] eq "Ess") {
1328: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1329: my $answer = $j + $numitems;
1330: my $answer_id = '';
1331: $qn_file[$qcount] = create_ess($newdir,$answer_id,$items[$j],$items[$answer],$qtype[$i],$j);
1332: push @newquestions, $question_id;
1333: $qcount ++;
1334: }
1335: }
1336: }
1337: }
1338: $r->print(qq|<tr><tr><td> </td><td><font face='arial,helvetica,sans-serif'>Individual problem files have been created from the problems included in the textbank file:
1339: <ul>|);
1340: for (my $i=0; $i<@qn_file; $i++) {
1341: my $display = $i+1;
1342: $r->print(qq|
1343: <li><b><a href="$linkdir/$qn_file[$i]">Problem $display file</a></b></li>
1344: |);
1345: }
1346: $r->print(qq|
1347: </ul></font></td></tr>
1348: <tr><td> </td>
1349: <td><font face='arial,helvetica,sans-serif'>The problems must be published before they can be used in a course.</font></td>
1350: |);
1351: } else {
1352: $r->print(qq|
1353: <tr>
1354: <td> </td>
1355: <td><font face='arial,helvetica,sans-serif'>No destination file was selected or created, so import of your questions could not proceed.
1356: Please return to the previous page and select a valid file into which to import the questions. </font>
1357: <input type="hidden" name="go" value="">
1358: <input type="hidden" name="page" value="$page">
1359: <input type="hidden" name="uploaduname" value="$uname">
1360: <input type="hidden" name="filename" value="$fn">
1361: <input type='hidden' name="page" value="$page">
1362: <input type="hidden" name="phase" value="three">
1363: <input type="hidden" name="qnumformat" value="$qnumformat">
1364: <input type="hidden" name="newdir" value="$newdir">
1365: |);
1366: for (my $i=0; $i<$blocks; $i++) {
1367: $r->print(qq|
1368: <input type="hidden" name="start_$i" value="$start[$i]">
1369: <input type="hidden" name="end_$i" value="$end[$i]">
1370: <input type="hidden" name="qtype_$i" value="$qtype[$i]">
1371: <input type="hidden" name="foilformat_$i" value="$foilformats[$i]">
1372: <input type="hidden" name="ansr_$i" value="$ansrtypes[$i]">
1373: |);
1374: }
1375: $r->print(<<"END_OF_FAIL");
1376: </td>
1377: </tr>
1378: <tr>
1379: <td colspan='2'>
1380: <table border='0' width='100%'>
1381: <tr>
1382: <td align='right'>
1383: <input type="button" name="backpage" value="Return to step 3" onClick="javascript:backPage()">
1384: </td>
1385: </tr>
1386: </table>
1387: </td>
1388: </tr>
1389: </table>
1390: </td>
1391: </tr>
1392: </table>
1393: </td>
1394: </tr>
1395: </table>
1396: </form>
1397: END_OF_FAIL
1398: return;
1399: }
1400: $r->print(<<"END_OF_BODY");
1401: </table>
1402: </td>
1403: </tr>
1404: </table>
1405: </td>
1406: </tr>
1407: <tr>
1408: <td colspan='2'>
1409: <input type="hidden" name="go" value="">
1410: <input type="hidden" name="page" value="$page">
1411: <input type="hidden" name="uploaduname" value="$uname">
1412: <input type="hidden" name="filename" value="$fn">
1413: <input type='hidden' name="page" value="$page">
1414: <input type="hidden" name="phase" value="one">
1415: <input type="hidden" name="qnumformat" value="$qnumformat">
1416: <input type="hidden" name="newdir" value="$newdir">
1417: </td>
1418: </tr>
1419: <tr>
1420: <td colspan='2'>
1421: <table border='0' width='100%'>
1422: <tr>
1423: <td align='left'>
1424: <input type='button' name='backtostart' value='Back to start page' onClick='javascript:backtoStart()'>
1425: </td>
1426: </tr>
1427: </table>
1428: </td>
1429: </tr>
1430: </table>
1431: </td>
1432: </tr>
1433: </table>
1434: </td>
1435: </tr>
1436: </table>
1437: </form>
1438: END_OF_BODY
1439: }
1440:
1441: sub question_count {
1442: my ($qnumformat,$textref) = @_;
1443: my $text_in = join "\n", @{$textref};
1444: $text_in = "\n ".$text_in;
1445: my $qpattern ='';
1446: if ($qnumformat eq "period") {
1447: $qpattern = '\d{1,}\.';
1448: } elsif ($qnumformat eq "paren") {
1449: $qpattern = '\(\d{1,}\)';
1450: } elsif ($qnumformat eq "number") {
1451: $qpattern = '\d{1,}';
1452: } elsif ($qnumformat eq "leadparen") {
1453: $qpattern = '\(\d{1,}';
1454: } elsif ($qnumformat eq "trailparen") {
1455: $qpattern = '\d{1,}\)';
1456: }
1457: my @questions = split/[\r\n\f]+\s?$qpattern\s?/,$text_in;
1458: my $qcount = scalar(@questions);
1459: $qcount = $qcount/2;
1460: $qcount = int($qcount);
1461: return $qcount;
1462: }
1463:
1464: sub file_split {
1465: my ($startsref,$endsref,$numsref,$qnumformat,$foilsref,$textref,$multpartsref,$numitems,$qtyperef,$blocks) = @_;
1466: my $text_in = join "\n", @{$textref};
1467: $text_in = "\n ".$text_in;
1468: my $dignum = length($numitems);
1469: my $numpat;
1470: if ($dignum > 1) {
1471: $numpat = ','.$dignum.'}';
1472: } else {
1473: $numpat = '}';
1474: }
1475: my $qpattern ='';
1476: if ($qnumformat eq "period") {
1477: $qpattern = '\d{1'.$numpat.'\.';
1478: } elsif ($qnumformat eq "paren") {
1479: $qpattern = '\(\d{1'.$numpat.'\)';
1480: } elsif ($qnumformat eq "number") {
1481: $qpattern = '\d{1'.$numpat;
1482: } elsif ($qnumformat eq "leadparen") {
1483: $qpattern = '\(\d{1'.$numpat;
1484: } elsif ($qnumformat eq "trailparen") {
1485: $qpattern = '\d{1'.$numpat.'\)';
1486: }
1.5 raeburn 1487: my @questions = split/[\r\n\f]+\s*$qpattern\s*/,$text_in;
1.1 raeburn 1488: # my @questions = split/\n\s\d{1,3}\.\s/,$text_in;
1489: shift @questions;
1490: my %multparts = ();
1491: for (my $i=0; $i<$blocks; $i++) {
1492: if (${$numsref}[$i] > 0) {
1.14 ! raeburn 1493: if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA") || (${$qtyperef}[$i] eq "Ord")) {
1.1 raeburn 1494: my $splitstr = '';
1495: if (${$foilsref}[$i] eq "lcperiod") {
1496: $splitstr = '[a-z]\.';
1497: } elsif (${$foilsref}[$i] eq "lcparen") {
1498: $splitstr = '\([a-z]\)';
1.5 raeburn 1499: } elsif (${$foilsref}[$i] eq "lconeparen") {
1500: $splitstr = '[a-z]\)';
1501: } elsif (${$foilsref}[$i] eq "lcdotparen") {
1502: $splitstr = '[a-z]\.\)';
1.1 raeburn 1503: } elsif (${$foilsref}[$i] eq "ucperiod") {
1504: $splitstr = '[A-Z]\.';
1505: } elsif (${$foilsref}[$i] eq "ucparen") {
1506: $splitstr = '\([A-Z]\)';
1.5 raeburn 1507: } elsif (${$foilsref}[$i] eq "uconeparen") {
1508: $splitstr = '[A-Z]\)';
1509: } elsif (${$foilsref}[$i] eq "ucdotparen") {
1510: $splitstr = '[A-Z]\.\)';
1.1 raeburn 1511: } elsif (${$foilsref}[$i] eq "romperiod") {
1512: $splitstr = '[ivx]+\.';
1513: } elsif (${$foilsref}[$i] eq "romparen") {
1514: $splitstr = '\([ivx]+\)';
1.5 raeburn 1515: } elsif (${$foilsref}[$i] eq "romoneparen") {
1516: $splitstr = '[ivx]+\)';
1517: } elsif (${$foilsref}[$i] eq "romdotparen") {
1518: $splitstr = '[ivx]+\.\)';
1.1 raeburn 1519: }
1520: for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
1.5 raeburn 1521: @{$multparts{$j}} = split/[\r\n\f]+\s*$splitstr\s*/,$questions[$j];
1.1 raeburn 1522: chomp(@{$multparts{$j}});
1523: }
1524: } elsif (${$qtyperef}[$i] eq "FIB") {
1525: for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
1526: @{$multparts{$j}} = ("$questions[$j]");
1527: }
1528: }
1529: }
1530: }
1531: %{$multpartsref} = %multparts;
1532: return @questions;
1533: }
1534:
1535: # create_mcq builds an MC, MA, Ord or FIB question
1536:
1537: sub create_mcq {
1538: my ($newdir,$qstnref,$answerref,$qtype,$qnum) = @_;
1539: $qnum ++;
1540: if (length($qnum) == 1) {
1541: $qnum = "00".$qnum;
1542: } elsif (length($qnum) == 2) {
1543: $qnum = "0".$qnum;
1544: }
1545: my $qstn = ${$qstnref}[0];
1546: my $numfoils = scalar(@{$qstnref}) - 1;
1547: my $datestamp = localtime;
1548: my $timestamp = time;
1549: my $libfile = 'question_'.$qnum;
1550: $libfile .= '.problem';
1551: my $numansrs = scalar(@{$answerref});
1552: my $output = qq|<problem>
1553: <startouttext />$qstn<endouttext />
1554: |;
1555:
1556: if ($qtype eq "MA") {
1557: $output .= qq|
1558: <optionresponse max="$numfoils" randomize="yes">
1559: <foilgroup options="('True','False')">
1560: |;
1561: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1562: $output .= " <foil name=\"foil".$k."\" value=\"";
1563: if (grep/^$k$/,@{$answerref}) {
1564: $output .= "True\" location=\"random\"";
1565: } else {
1566: $output .= "False\" location=\"random\"";
1567: }
1568: $output .= "\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1569: }
1570: chomp($output);
1571: $output .= qq|
1572: </foilgroup>
1573: </optionresponse>
1574: </problem>
1575: |;
1576: }
1577: if ($qtype eq "MC") {
1578: $output .= qq|
1579: <radiobuttonresponse max="$numfoils" randomize="yes">
1580: <foilgroup>
1581: |;
1582: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1583: $output .= " <foil name=\"foil".$k."\" value=\"";
1584: if (grep/^$k$/,@{$answerref}) {
1585: $output .= "true\" location=\"";
1586: } else {
1587: $output .= "false\" location=\"";
1588: }
1589: if (lc (${$qstnref}[$k+1]) =~ m/^\s?([Aa]ll)|([Nn]one)\sof\sthe\sabove\.?/) {
1590: $output .= "bottom\"";
1591: } else {
1592: $output .= "random\"";
1593: }
1594: $output .= "\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1595: }
1596: chomp($output);
1597: $output .= qq|
1598: </foilgroup>
1599: </radiobuttonresponse>
1600: </problem>
1601: |;
1602: }
1603:
1604: if ($qtype eq "Ord") {
1605: $output .= qq|
1606: <rankresponse max="$numfoils" randomize="yes">
1607: <foilgroup>
1608: |;
1609: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1.14 ! raeburn 1610: my $ansval;
! 1611: my $num = 0;
! 1612: for (my $i=0; $i<@{$answerref}; $i++) {
! 1613: if ($$answerref[$i] =~ /=/) {
! 1614: my @tied = split(/=/,$$answerref[$i]);
! 1615: foreach my $tie (@tied) {
! 1616: if ($k == $tie) {
! 1617: $ansval = $num + 1;
! 1618: last;
! 1619: }
! 1620: }
! 1621: $num += scalar(@tied);
! 1622: } elsif ($k == $$answerref[$i]) {
! 1623: $ansval = $num + 1;
! 1624: last;
! 1625: } else {
! 1626: $num ++;
! 1627: }
! 1628: }
! 1629: $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$ansval."\"><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1.1 raeburn 1630: }
1631: chomp($output);
1632: $output .= qq|
1633: </foilgroup>
1634: </rankresponse>
1635: </problem>
1636: |;
1637: }
1638:
1639: if ($qtype eq "FIB") {
1640: my $numerical = 1;
1641: for (my $i=0; $i<@{$answerref}; $i++) {
1642: if (${$answerref}[$i] =~ m/([^\d\.]|\.\.)/) {
1643: $numerical = 0;
1644: }
1645: }
1646: if ($numerical) {
1647: my $numans;
1648: my $tol;
1649: if (@{$answerref} == 1) {
1650: $tol = 5;
1651: $numans = $$answerref[0];
1652: } else {
1.2 raeburn 1653: my $min = $$answerref[0];
1654: my $max = $$answerref[0];
1655: for (my $i=1; $i<@{$answerref}; $i++) {
1656: if ($$answerref[$i]<=$min) {
1.1 raeburn 1657: $min = $$answerref[$i];
1.2 raeburn 1658: } elsif ($$answerref[$i] >= $max) {
1.1 raeburn 1659: $max = $$answerref[$i];
1660: }
1661: }
1662: $numans = ($max + $min)/2;
1663: $tol = 100*($max - $min)/($numans*2);
1664: }
1665: $output .= qq|
1666: <numericalresponse answer="$numans">
1667: <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
1668: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />
1669: <textline />
1670: </numericalresponse>
1671: </problem>
1672: |;
1673: } else {
1674: if (@{$answerref} == 1) {
1675: $output .= qq|
1676: <stringresponse answer="$$answerref[0]" type="ci">
1677: <textline>
1678: </textline>
1679: </stringresponse>
1680: </problem>
1681: |;
1682: } else {
1683: for (my $i=0; $i<@{$answerref}; $i++) {
1684: ${$answerref}[$i] =~ s/\|/\|/g;
1685: }
1686: my $regexpans = join('|',@{$answerref});
1687: $regexpans = '/('.$regexpans.')/';
1688: $output .= qq|
1689: <stringresponse answer="$regexpans" type="re">
1690: <textline>
1691: </textline>
1692: </stringresponse>
1693: </problem>
1694: |;
1695: }
1696: }
1697: }
1698: open(PROB,">$newdir/$libfile");
1699: print PROB $output;
1700: close PROB;
1701: return $libfile;
1702: }
1703:
1704: # create_ess builds an essay or True/False question
1705:
1706: sub create_ess {
1707: my ($newdir,$answer_id,$qstn,$answertxt,$qtype,$qnum) = @_;
1708: $qnum ++;
1709: if (length($qnum) == 1) {
1710: $qnum = "00".$qnum;
1711: } elsif (length($qnum) == 2) {
1712: $qnum = "0".$qnum;
1713: }
1714: my $libfile = 'question_'.$qnum;
1715: $libfile .= '.problem';
1716: my $output = qq|<problem>
1717: <startouttext />$qstn<endouttext />|;
1718:
1719: my $answer = '';
1720: my $answerlog = '';
1721: if ($qtype eq "Ess") {
1722: $output .= qq|
1723: <essayresponse>
1724: <textfield></textfield>
1725: </essayresponse>
1726: <postanswerdate>
1.13 raeburn 1727: <startouttext />
1.1 raeburn 1728: $answertxt
1.13 raeburn 1729: <endouttext />
1.1 raeburn 1730: </postanswerdate>
1731: </problem>|;
1732: } elsif ($qtype eq "TF") {
1733: $answer = $answer_id;
1734: $output .= qq|
1735: <radiobuttonresponse max="2" randomize="yes">
1736: <foilgroup>
1737: |;
1738: $output .= " <foil name=\"foil0\" value=\"true\" location=\"random\"><startouttext />";
1739: if ($answer_id) {
1740: $output .= "False";
1741: } else {
1742: $output .= "True";
1743: }
1744: $output .= "<endouttext /></foil>\n";
1745: $output .= " <foil name=\"foil1\" value=\"false\" location=\"random\"><startouttext />";
1746: if ($answer_id) {
1747: $output .= "True";
1748: } else {
1749: $output .= "False";
1750: }
1751: $output .= qq|<endouttext /></foil>
1752: </foilgroup>
1753: </radiobuttonresponse>
1754: </problem>|;
1755: }
1756: open(PROB,">$newdir/$libfile");
1757: print PROB $output;
1758: close PROB;
1759: return $libfile;
1760: }
1761:
1762: sub file_error {
1763: my ($r,$uname,$fn,$current_page);
1764: $r->print("No data here");
1765: }
1766:
1767: # ---------------------------------------------------------------- Main Handler
1768: sub handler {
1769: my $r=shift;
1770: my $uname;
1771: my $udom;
1772: my $javascript = '';
1773: my $page_name = '';
1774: my $current_page = '';
1775: my $qcount = '';
1776: #
1777: # phase two: re-attach user
1778: #
1.6 albertel 1779: if ($env{'form.uploaduname'}) {
1780: $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
1781: $env{'form.filename'};
1.1 raeburn 1782: }
1783: ($uname,$udom)=
1.6 albertel 1784: &Apache::loncacc::constructaccess($env{'form.filename'},
1.1 raeburn 1785: $r->dir_config('lonDefDomain'));
1786: unless (($uname) && ($udom)) {
1787: $r->log_reason($uname.' at '.$udom.
1.6 albertel 1788: ' trying to publish file '.$env{'form.filename'}.
1.1 raeburn 1789: ' - not authorized',
1790: $r->filename);
1791: return HTTP_NOT_ACCEPTABLE;
1792: }
1793:
1794: my $fn;
1795: my $badfile = 0;
1.6 albertel 1796: if ($env{'form.filename'}) {
1797: $fn=$env{'form.filename'};
1.1 raeburn 1798: $fn=~s/^http\:\/\/[^\/]+\///;
1799: $fn=~s/^\///;
1.11 albertel 1800: $fn=~s{(~|priv/)($LONCAPA::username_re)}{};
1.1 raeburn 1801: $fn=~s/\/+/\//g;
1802: } else {
1.6 albertel 1803: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.1 raeburn 1804: ' unspecified filename for upload', $r->filename);
1805: return HTTP_NOT_FOUND;
1806: }
1807: my $pathname = &File::Basename::dirname($fn);
1808: my $fullpath = '/priv/'.$uname.$pathname;
1809: unless ($pathname eq '/') {
1810: $fullpath .= '/';
1811: }
1812:
1813: my $dirpath = '/home/'.$uname.'/public_html';
1814:
1815: my @text = ();
1.6 albertel 1816: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1817: if (-e "$dirpath$fn") {
1818: open(TESTBANK,"<$dirpath$fn");
1819: @text = <TESTBANK>;
1820: close(TESTBANK);
1821: } else {
1822: $badfile = 1;
1823: }
1824: }
1825:
1826: # ----------------------------------------------------------- Start page output
1827: &Apache::loncommon::content_type($r,'text/html');
1828: $r->send_http_header;
1829:
1.10 albertel 1830: my %loadentries;
1.6 albertel 1831: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1832: $current_page = &display_control();
1833: my @PAGES = ('Welcome','Blocks','Format','Target','Confirmation');
1834: $page_name = $PAGES[$current_page];
1835:
1836: if ($page_name eq 'Blocks') {
1.10 albertel 1837: $loadentries{'onload'} = "setElements()";
1.1 raeburn 1838: &jscript_one(\$javascript);
1839: } elsif ($page_name eq 'Format') {
1.6 albertel 1840: $qcount = question_count($env{'form.qnumformat'},\@text);
1.1 raeburn 1841: &jscript_two(\$javascript,$qcount);
1842: } elsif ($page_name eq 'Target') {
1.6 albertel 1843: if ($env{'form.go'} eq "PreviousPage") {
1.10 albertel 1844: $loadentries{'onload'} = "setElements()";
1.1 raeburn 1845: }
1846: &jscript_three($fullpath,\$javascript);
1847: } elsif ($page_name eq 'Confirmation') {
1848: &jscript_four(\$javascript,$fullpath);
1849: }
1.8 albertel 1850: }
1851:
1852: $javascript = "<script type=\"text/javascript\">\n//<!--\n".
1853: $javascript."\n// --></script>\n";
1854:
1855: $r->print(&Apache::loncommon::start_page('Upload testbank questions to Construction Space',
1856: $javascript,
1.10 albertel 1857: {'add_entries' => \%loadentries}));
1.1 raeburn 1858:
1.6 albertel 1859: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1 raeburn 1860: $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
1861: &mt(' at ').$udom.'</font></h3>');
1862: }
1863:
1.6 albertel 1864: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1865: if ($badfile) {
1866: &file_error($r,$uname,$fn,$current_page);
1867: } else {
1868: &display_zero ($r,$uname,$fn,$current_page,$fullpath) if $page_name eq 'Welcome';
1869: &display_one ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Blocks';
1870: &display_two ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Format';
1871: &display_three ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Target';
1872: &final_display ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Confirmation';
1873: }
1.6 albertel 1874: } elsif ($env{'form.phase'} eq 'two') {
1.1 raeburn 1875: my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'testbank');
1876: if ($flag eq 'ok') {
1877: my $current_page = 0;
1878: &display_zero($r,$uname,$fn,$current_page,$fullpath);
1879: }
1880: } else {
1881: &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'testbank');
1882: }
1.8 albertel 1883: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1884: return OK;
1885: }
1886: 1;
1887: __END__
1888:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>