Annotation of loncom/publisher/testbankimport.pm, revision 1.6
1.3 albertel 1: # Handler for parsing text upload problem descriptions into .problems
1.6 ! albertel 2: # $Id: testbankimport.pm,v 1.5 2004/08/05 21:08:24 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::Log();
34: use Apache::lonnet;
35: use HTML::Entities();
36: use Apache::lonlocal;
37: use Apache::lonupload;
38: use File::Basename();
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: }
351: $$jsref = <<"END_OF_ONE";
352: function verify() {
353: if ((document.forms.dataForm.newdir.value == '') || (!document.forms.dataForm.newdir.value)) {
354: alert("Step 4: You must choose a destination directory for the import")
355: return false
356: }
357: return true
358: }
359:
360: function nextPage() {
361: if (verify()) {
362: document.forms.dataForm.go.value="NextPage"
363: document.forms.dataForm.submit()
364: }
365: }
366: function backPage() {
367: document.forms.dataForm.go.value="PreviousPage"
368: document.forms.dataForm.submit()
369: }
370:
371: function createWin() {
372: document.dataForm.newdir.value = "";
373: newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
374: newWindow.document.open()
375: newWindow.document.write("<html><head><title>Create Testbank directory</title><meta http-equiv='pragma' content='no-cache'>\\n")
376: newWindow.document.write("</head><body bgcolor='#CCFFDD' topmargin='0' leftmargin='0' marginheight='0'marginwidth='0' rightmargin='0'>\\n")
377: newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")
378: newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='430' bgcolor='#CCFFDD'>\\n")
379: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
380: newWindow.document.write("<td><h3>Location: <tt>$fullpath</tt></h3><h3>New Directory</h3></td></tr>\\n")
381: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
382: newWindow.document.write("<td><form name='fileaction' action='/adm/cfile' method='post'>\\n")
383: newWindow.document.write("<font face='arial,helvetica,sans-serif'>Enter the name of the new directory where you will store the converted testbank questions<br /><br />")
384: newWindow.document.write("<input type='hidden' name='filename' value='$fullpath'>")
385: newWindow.document.write("<input type='hidden' name='action' value='newdir'>")
386: newWindow.document.write("<input type='hidden' name='callingmode' value='testbank'>")
387: newWindow.document.write("$fullpath<input type='text' name='newfilename' value=''/>")
388: newWindow.document.write("<input type='button' value='Go' onClick='document.fileaction.submit();' />")
389: newWindow.document.write("</td></tr>\\n")
390: newWindow.document.write("</table></body></html>")
391: newWindow.document.close()
392: newWindow.focus()
393: }
394: END_OF_ONE
395: if ($source eq "PreviousPage") {
396: $$jsref .= qq|
397: function setElements() {
398: var iter = 0
399: var selParam = 0
400: |;
1.6 ! albertel 401: foreach my $item (keys %env) {
1.1 raeburn 402: if ($item =~ m/^form\.(\w+)$/) {
403: my $name = $1;
1.6 ! albertel 404: my $value = $env{"form.$name"};
1.1 raeburn 405: unless ($value eq "") {
406: if ($name eq "newdir") {
407: $$jsref .= qq( document.forms.dataForm.$name.value = "$value"\n);
408: }
409: }
410: }
411: }
412: $$jsref .= "}";
413: }
414: }
415:
416:
417: # ---------------------------------------------------------------- Jscript Four
418: sub jscript_four {
419: my ($jsref,$fullpath) = @_;
420: $$jsref = qq|
421: function backtoStart() {
422: document.location.href="$fullpath"
423: }
424: function backpage() {
425: document.forms.verify.go.value="PreviousPage"
426: document.forms.verify.submit()
427: }
428: |;
429: }
430:
431: # ---------------------------------------------------------------- Display Zero
432: sub display_zero {
433: my ($r,$uname,$fn,$page,$fullpath) = @_;
434: $r->print(qq|
435: <table border='0' cellspacing='0' cellpadding='0' width='100%'>
436: <tr>
437: <td> </td>
438: <td colspan='2'><font face='arial,helvetica,sans-serif'>
439: 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.
440: <ol>
441: <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>
442: <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>
443: <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>
444: <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.
445: <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.</li>
446: </ol>
447: Five steps are involved in the import process.
448: <ol>
449: <li>Upload your text file to the server.|);
450:
451: if ($fn eq '') {
452: $r->print("<b>Incomplete</b>. Please return to the <a href='$fullpath'>construction space menu<a> to upload a file");
453: } else {
454: $r->print(" <b>Completed</b> - successful upload of <i>$fn</i>");
455: }
456: $r->print(qq|</li>
457: <li>Provide information about the question format - i.e., question numbering style, and the number of blocks of questions of each question type.</li>
458: <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>
459: <li>Create a new directory where you will store the converted testbank questions.</li>
460: <li>Complete the import of questions to the selected pool.</li>
461: </ol>
462: </font>
463: </td>
464: </tr>
465: </table>
466: <br />
467: <br />
468: <form name="info" method="post">
469: <input type="hidden" name="uploaduname" value="$uname">
470: <input type="hidden" name="filename" value="$fn">
471: <input type="hidden" name="page" value="$page">
472: <input type="hidden" name="phase" value="three">
473: <input type="hidden" name="go" value="NextPage">
474: <table border="0" width="100%">
475: <tr>
476: <td align='left'>
477: <input type="button" name="goback" value="Exit Now" onClick="javascript:location.href='$fullpath'">
478: </td>
479: <td align='right'>
480: <input type="button" name="nextpage" value="Continue to step 2" onClick="javascript:submit()">
481: </td>
482: </tr>
483: </table>
484: </form>
485: |);
486: }
487:
488:
489: # ---------------------------------------------------------------- Display One
490:
491: sub display_one {
492: my ($r,$uname,$fn,$page,$textref) = @_;
493: $r->print(qq|
494: <form method='post' name='display'>
495: <table border='0' cellspacing='0' cellpadding='3' width='100%'>
496: <tr bgcolor='#ccddaa'>
497: <td> </td>
498: <td align='left'>
499: <h3><font face='arial,helvetica,sans-serif'>Step 2: Identification of blocks of questions</b> </font></h3>
500: </td>
501: </tr>
502: <tr>
503: <td colspan='2'> </td>
504: </tr>
505: <tr>
506: <td colspan='2'>
507: <table border="0" cellspacing="0" cellpadding="2">
508: <tr>
509: <td> </td>
510: <td colspan='2'>
511: <font face='arial,helvetica,sans-serif'><b>Testbank data uploaded to the server:</b></font>
512: </td>
513: </tr>
514: <tr>
515: <td colspan='3'> </td>
516: </tr>
517: <tr>
518: <td> </td>
519: <td colspan='2'>
520: <textarea name="rawdata" cols="70" rows="6" wrap="virtual" align="center">
521: |);
522: foreach my $line (@{$textref}) {
523: $line =~ s/\n//g;
524: $r->print("$line\n");
525: }
526: $r->print(qq|
527: </textarea>
528: </td>
529: </tr>
530: <tr>
531: <td colspan='3'> </td>
532: </tr>
533: <tr>
534: <tr>
535: <td colspan='3'> </td>
536: </tr>
537: <tr bgcolor='#ccddaa'>
538: <td> </td>
539: <td align='left' valign='middle'><img src="/res/adm/pages/bl_step1.gif">
540: </td>
541: <td>
542: <font face='arial,helvetica,sans-serif'><b>
543: Select the format of the question number</b> [e.g., 1, 1., 1), (1 or (1)].
544: <select name="qnumformat">
545: <option value = "-1" selected>Please Select
546: <option value="number">1
547: <option value="period">1.
548: <option value="paren">(1)
549: <option value="leadparen">(1
550: <option value="trailparen">1)
551: </select>
552: </font>
553: </td>
554: </tr>
555: <tr>
556: <td colspan='3'> </td>
557: </tr>
558: <tr>
559: <td> </td>
560: <td colspan='2'><font face='arial,helvetica,sans-serif'>
561: 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>
562: </tr>
563: <tr>
564: <td colspan="3"> </td>
565: </tr>
566: <tr>
567: <td> </td>
568: <td colspan='2'>
569: <font face='arial,helvetica,sans-serif'>
570: For example, you would select <b>1.</b> if your text file contained the following questions:<br><br>
571: 1. The capital of the USA is ..<br />
572: (a) Washington D.C.<br />
573: (b) New York<br />
574: (c) Los Angeles<br />
575: <br />
576: 2. The capital of Canada is ..<br />
577: (a) Toronto<br />
578: (b) Vancouver<br />
579: (c) Ottawa<br />
580: <br />
581: 3. Describe an experiment you could conduct to measure c, the speed of light in a vacuum. <br /><br />
582: 1. (a)<br />
583: 2. (c)<br />
584: 3. <br />
585: </td>
586: <tr>
587: <td colspan="3"> </td>
588: </tr>
589: <tr bgcolor='#ccddaa'>
590: <td> </td>
591: <td><img src='/res/adm/pages/bl_step2.gif' align='left' valign='middle'>
592: </td>
593: <td>
594: <font face='arial,helvetica,sans-serif'><b>
595: Please indicate the number of blocks of different question types in the text file.</b>
596: <input type="text" name="blocks" value="" size="5">
597: </td>
598: </tr>
599: <tr>
600: <td colspan="3"> </td>
601: </tr>
602: <tr>
603: <td> </td>
604: <td colspan='2'>
605: <font face='arial,helvetica,sans-serif'>
606: For example, you would enter <b>6</b> if your text file contained the following sequence of questions:<br><br>
607: 10 multiple choice questions<br>
608: 5 essay questions<br>
609: 5 fill-in-the-blank questions<br>
610: 5 multiple answer questions<br>
611: 4 multiple choice questions<br>
612: 3 essay questions<br>
613: </font>
614: </td>
615: </tr>
616: <tr>
617: <td colspan='3'> </td>
618: </tr>
619: <tr>
620: <td> </td>
621: <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>
622: </tr>
623: <tr>
624: <td colspan='3'> </td>
625: </tr>
626: <tr>
627: <td colspan='3'>
628: <table border='0' width="100%" cellspacing='0' cellpadding='2'>
629: <tr>
630: <td align='left'>
631: <input type="button" name="backpage" value="Go back to step 1" onClick="javascript:backPage()">
632: </td>
633: <td align='right'>
634: <input type="button" name="nextpage" value="Continue to step 3" onClick="javascript:nextPage()">
635: </td>
636: </tr>
637: </table>
638: <input type="hidden" name="page" value ="$page">
639: <input type="hidden" name="go" value="">
640: <input type="hidden" name="uploaduname" value="$uname">
641: <input type="hidden" name="filename" value="$fn">
642: <input type="hidden" name="phase" value="three">
643: </td>
644: </tr>
645: </table>
646: </td>
647: </tr>
648: </table>
649: </form>
650: |);
651: }
652:
653: # ---------------------------------------------------------------- Display Two
654:
655: sub display_two {
656: my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
1.6 ! albertel 657: my $blocks = $env{'form.blocks'};
! 658: my $qnumformat = $env{'form.qnumformat'};
1.1 raeburn 659: my @types = ("MC","MA","TF","Ess","FIB","Ord");
660: my %typenames = (
661: MC => "Multiple Choice",
662: TF => "True/False",
663: MA => "Multiple Answer",
664: Ess => "Essay",
665: FIB => "Fill-in-the-blank",
666: Ord => "Ranking/ordering",
667: );
668: my %qnumtypes = (
669: number => "1",
670: period => "1.",
671: paren => "(1)",
672: leadparen => "(1",
673: trailparen => "1)",
674: );
675: my @bgcolors = ('#ffffff','#eeeeee');
676: my $bl1st = '';
677: my $bl1end = '';
678: if ($blocks == 1) {
679: $bl1st = '1';
680: $bl1end = $qcount;
681: }
682: $r->print(<<"END_OF_FUNC");
683: <h3><font face='arial,helvetica,sans-serif'>Step 3: Classification of blocks</b> </font></h3>
684: <form method='post' name='display'>
685: <table border='0' cellspacing='0' cellpadding ='0'>
686: <tr>
687: <td colspan='2'> </td>
688: </tr>
689: <tr>
690: <td colspan='2'>
691: <table border="0" cellspacing="0" cellpadding="0">
692: <tr>
693: <td> </td>
694: <td><font face='arial,helvetica,sans-serif'>
695: 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>
696: 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>
697: </td>
698: </tr>
699: <tr>
700: <td colpsan='2'> </td>
701: </tr>
702: <tr>
703: <td> </td>
704: <td><font face='arial,helvetica,sans-serif'>
705: 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.
706: </td>
707: </tr>
708: <tr>
709: <td colpsan='2'> </td>
710: </tr>
711: <tr>
712: <td> </td>
713: <td>
714: <font face='arial,helvetica,sans-serif'>The following data were uploaded to the server</font><br>
715: <textarea name="rawdata" cols="70" rows="6" wrap="virtual" align="center">
716: END_OF_FUNC
717: foreach my $line (@{$textref}) {
718: $line =~ s/\n//g;
719: $r->print("$line\n");
720: }
721: $r->print(qq|
722: </textarea>
723: </td>
724: </tr>
725: <tr>
726: <td colspan='2'> </td>
727: </tr>
728: <tr bgcolor='#ccddaa'>
729: <td><img src='/res/adm/pages/bl_step3.gif' align='left' valign='middle'>
730: </td>
731: <td width='100%' align='left'>
732: <font size='+1' face='arial,helvetica,sans-serif'><b>Information about question types and formats in each block.</b></font>
733: </td>
734: </tr>
735: <tr>
736: <td colspan='2'> </td>
737: </tr>
738: <tr>
739: <td> </td>
740: <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>
741: </td>
742: </tr>
743: <tr>
744: <td colspan='2'> </td>
745: </tr>
746: <tr>
747: <td> </td>
748: <td>
749: <table border="0" cellspacing="0" cellpadding="0" bgcolor="#000000" align="left">
750: <tr>
751: <td>
752: <table border="1" valign="top" align="center" width='100%'>
753: <tr bgcolor="#eef6f6" align="left">
754: <td>
755: <table border='0' cellspacing='1' cellpadding='1' align='left' width='100%'>
756: <tr bgcolor='#CCDDAA' align='center' valign='middle'>
757: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
758: <b>Block</b> </font>
759: </td>
760: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
761: <b>First number</b> </font>
762: </td>
763: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
764: <b>Last number</b> </font>
765: </td>
766: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
767: <b>Question type</b> </font>
768: </td>
769: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
770: <b>Foil format</b> </font>
771: </td>
772: <td align="center" valign="middle" height='10'><font face='arial,helvetica,sans-serif'>
773: <b>Answer format</b> </font>
774: </td>
775: </tr>
776: |);
777: for (my $i=0; $i<$blocks; $i++) {
778: my $iter = $i+1;
779: my $rowcol = $i%2;
780: $r->print(qq|
781: <tr bgcolor="$bgcolors[$rowcol]">
782: <td align="left">
783: <font face='arial,helvetica,sans-serif'> $iter.</font>
784: </td>
785: <td align="left">
786: <input type="text" name="start_$i" value="$bl1st" size="5">
787: </td>
788: <td align="left">
789: <input type="text" name="end_$i" value="$bl1end" size="5">
790: </td>
791: <td align="left">
792: <font face='arial,helvetica,sans-serif'>
793: <select name="qtype_$i" onChange="colSet($i)">
794: <option value= "-1" selected>Please Select
795: |);
796: foreach my $qtype (@types) {
797: $r->print(qq|<option value="$qtype">$typenames{$qtype}|);
798: }
799: $r->print(qq|
800: </select>
801: </font>
802: </td>
803: <td align="left">
804: <select name="foilformat_$i">
805: <option value="-1"><--- Set type
806: </select>
807: </td>
808: <td align="left">
809: <select name="ansr_$i">
810: <option value="-1"><--- Set type
811: </select>
812: </td>
813: </tr>
814: |);
815: }
816: $r->print(qq|
817: </table>
818: </td>
819: </tr>
820: </table>
821: </td>
822: </tr>
823: </table>
824: </td>
825: </tr>
826: <tr>
827: <td colspan="2"> </td>
828: </tr>
829: <tr>
830: <td> </td>
831: <td>
832: <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>
833: <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>
834: </td>
835: </tr>
836: <tr>
837: <td colspan='2'> </td>
838: </tr>
839: <tr>
840: <td colspan='2'>
841: <input type="hidden" name="blocks" value="$blocks">
842: <input type="hidden" name="qnumformat" value="$qnumformat">
843: <table border='0' width="100%" cellspacing='0' cellpadding='2'>
844: <tr>
845: <td align='left'>
846: <input type="button" name="backpage" value="Go back to step 2" onClick="javascript:backPage()">
847: </td>
848: <td align='right'>
849: <input type="button" name="nextpage" value="Continue to step 4" onClick="javascript:nextPage()">
850: </td>
851: </tr>
852: </table>
853: <input type="hidden" name="page" value ="$page">
854: <input type="hidden" name="go" value="">
855: <input type="hidden" name="uploaduname" value="$uname">
856: <input type="hidden" name="filename" value="$fn">
857: <input type="hidden" name="phase" value="three">
858: </form>
859: </td>
860: </tr>
861: </table>
862: </td>
863: </tr>
864: </table>
865: |);
866: }
867: # ---------------------------------------------------------------- Display Three
868: sub display_three {
869: my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
1.6 ! albertel 870: my $qnumformat = $env{'form.qnumformat'};
! 871: my $filename = $env{'form.filename'};
! 872: my $source = $env{'form.go'};
! 873: my $blocks = $env{'form.blocks'};
1.1 raeburn 874: my @items = ();
875: my @bgcolors = ('#ffffff','#eeeeee');
876: my @types = ("MC","MA","TF","Ess","FIB","Ord");
877: 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");
878: 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");
879: my @start = ();
880: my @end = ();
881: my @nums = ();
882: my @qtype = ();
883: my @foilformats = ();
884: my @ansrtypes = ();
885: my %multparts = ();
886: my $numitems = 0;
887: for (my $i=0; $i<$blocks; $i++) {
1.6 ! albertel 888: if (($env{"form.start_$i"} ne '') && ($env{"form.end_$i"} ne '')) {
! 889: $start[$i] = $env{"form.start_$i"};
! 890: $end[$i] = $env{"form.end_$i"};
1.1 raeburn 891: $nums[$i] = $end[$i]-$start[$i] +1;
1.6 ! albertel 892: $qtype[$i] = $env{"form.qtype_$i"};
1.1 raeburn 893: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.6 ! albertel 894: $foilformats[$i] = $env{"form.foilformat_$i"};
1.1 raeburn 895: } else {
896: $foilformats[$i] = '';
897: }
898: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1.6 ! albertel 899: $ansrtypes[$i] = $env{"form.ansr_$i"};
1.1 raeburn 900: } else {
901: $ansrtypes[$i] = '';
902: }
903: } else {
904: $nums[$i] = 0;
905: }
906: $numitems += $nums[$i];
907: }
908:
909: my $import = join//,@{$textref};
910: @items = &file_split(\@start,\@end,\@nums,$qnumformat,\@foilformats,$textref,\%multparts,$numitems,\@qtype,$blocks);
911: $r->print(<<"END_OF_ONE");
912: <h3><font face='arial,helvetica,sans-serif'>Step 4: Review and selection of destination directory</b> </font></h3>
913: <form name="dataForm" method="post">
914: <table border='0' bgcolor='#CCFFDD' cellspacing='0' cellpadding ='0'>
915: <tr>
916: <td colspan='2'>
917: <table border='0' cellspacing='0' cellpadding='0'>
918: <tr>
919: <td colspan='2'> </td>
920: </tr>
921: <tr>
922: <td> </td>
923: <td><font face='arial,helvetica,sans-serif'><b>
924: Based on your previous responses your data have been split into a total of $numitems questions.</b>
925: </td>
926: </tr>
927: <tr>
928: <td colspan='2'> </td>
929: </tr>
930: <tr>
931: <td> </td>
932: <td width="80%" bgcolor="#000000" align="left">
933: <table width="100%" border="0" cellpadding="1" cellspacing="0">
934: <tr>
935: <td width="100%" bgcolor="#000000">
936: <table border="0" cellspacing="0" cellpadding="1" width="100%">
937: <tr>
938: <td width="100%" bgcolor="#000000">
939: <table border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff" width="100%">
940: <tr>
941: <td bgcolor="#CCFFDD" width="100%">
942: <table border='0' cellspacing='1' cellpadding='2' align='left' width= '100%'>
943: <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>
944: END_OF_ONE
945: for (my $j=0; $j<$numitems; $j++) {
946: my $qnum = $j+1;
947: my $rowcol = $j%2;
948: $rowcol = @bgcolors[$rowcol];
949: for (my $i=0; $i<$blocks; $i++) {
950: if ($nums[$i] > 0) {
951: if (($j+1 >= $start[$i]) && ($j+1 <= $end[$i])) {
952: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA")) {
953: for (my $k=0; $k<@{$multparts{$j}}; $k++) {
954: if ($k == 0) {
955: $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|);
956: } else {
957: my $foiltag = '';
958: if ($foilformats[$i] eq "lcperiod") {
959: $foiltag = $alphabet[$k-1].'.';
960: } elsif ($foilformats[$i] eq "lcparen") {
961: $foiltag = '('.$alphabet[$k-1].')';
1.5 raeburn 962: } elsif ($foilformats[$i] eq "lconeparen") {
963: $foiltag = $alphabet[$k-1].')';
964: } elsif ($foilformats[$i] eq "lcdotparen") {
965: $foiltag = $alphabet[$k-1].'.)';
1.1 raeburn 966: } elsif ($foilformats[$i] eq "ucperiod") {
967: $foiltag = $alphabet[$k-1].'.';
968: $foiltag =~ tr/a-z/A-Z/;
969: } elsif ($foilformats[$i] eq "ucparen") {
970: $foiltag = '('.$alphabet[$k-1].')';
971: $foiltag =~ tr/a-z/A-Z/;
1.5 raeburn 972: } elsif ($foilformats[$i] eq "uconeparen") {
973: $foiltag = $alphabet[$k-1].')';
974: $foiltag =~ tr/a-z/A-Z/;
975: } elsif ($foilformats[$i] eq "ucdotparen") {
976: $foiltag = $alphabet[$k-1].'.)';
977: $foiltag =~ tr/a-z/A-Z/;
1.1 raeburn 978: } elsif ($foilformats[$i] eq "romperiod") {
979: $foiltag = $romans[$k-1].'.';
980: } elsif ($foilformats[$i] eq "romparen") {
981: $foiltag = '('.$romans[$k-1].')';
1.5 raeburn 982: } elsif ($foilformats[$i] eq "romoneparen") {
983: $foiltag = $romans[$k-1].')';
984: } elsif ($foilformats[$i] eq "romdotparen") {
985: $foiltag = $romans[$k-1].'.)';
986: }
1.1 raeburn 987: $r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|);
988: }
989: }
990: $r->print(qq|<br></font></td><td bgcolor="$rowcol" valign='top'><font face='arial,helvetica,sans-serif'>$items[$j+$numitems]</font></td></tr>|);
991: } else {
992: $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>|);
993: }
994: last;
995: }
996: }
997: }
998: }
999: $r->print(qq|
1000: </table>
1001: </td>
1002: </tr>
1003: </table>
1004: </td>
1005: </tr>
1006: </table>
1007: </td>
1008: </tr>
1009: </table>
1010: </td>
1011: </tr>
1012: <tr>
1013: <td colspan='2'> </td>
1014: </tr>
1015: <tr bgcolor='#ccddaa'>
1016: <td width='30' align='top'><img src='/res/adm/pages/bl_step4.gif'>
1017: </td>
1018: <td width='100%' align='left'>
1019: <font size='+1' face='arial,helvetica,sans-serif'><b>Create a directory to store your testbank questions.</b></font>
1020: </td>
1021: </tr>
1022: <tr>
1023: <td colspan='2'> </td>
1024: </tr>
1025: <tr>
1026: <td> </td>
1027: <td>
1028: <font face='Arial,Helvetica,sans-serif'>
1029: Please choose a destination LON-CAPA directory in which to store your uploaded questions.
1030: <input type="button" name="createdir" value="Create Directory" onClick="javascript:createWin()"><input type="hidden" name="newdir" value=""></font></td>
1031: </tr>
1032: <tr>
1033: <td colspan='2'> </td>
1034: </tr>
1035: <tr>
1036: <td> </td>
1037: <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>
1038: </tr>
1039: <tr>
1040: <td colspan='2'>
1041: <input type='hidden' name="go" value="">
1042: <input type='hidden' name="qnumformat" value="$qnumformat">
1043: <input type='hidden' name="blocks" value="$blocks">
1044: <input type="hidden" name="uploaduname" value="$uname">
1045: <input type="hidden" name="filename" value="$fn">
1046: <input type='hidden' name="page" value="$page">
1047: <input type="hidden" name="phase" value="three">
1048: |);
1049: for (my $i=0; $i<$blocks; $i++) {
1050: $r->print(qq|
1051: <input type='hidden' name="start_$i" value="$start[$i]">
1052: <input type='hidden' name="end_$i" value="$end[$i]">
1053: <input type='hidden' name="qtype_$i" value="$qtype[$i]">
1054: |);
1055: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1056: $r->print(qq|
1057: <input type='hidden' name="foilformat_$i" value="$foilformats[$i]">
1058: |);
1059: }
1060: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1061: $r->print(qq|
1062: <input type='hidden' name="ansr_$i" value="$ansrtypes[$i]">
1063: |);
1064: }
1065: }
1066: $r->print(qq|
1067: </td>
1068: </tr>
1069: <tr>
1070: <td colspan='2'> <br /><br /></td>
1071: </tr>
1072: <tr>
1073: <td colspan='2'>
1074: <table border='0' cellspacing='0' cellpadding='0' width="100%">
1075: <tr>
1076: <td align='left'>
1077: <input type="button" name="backpage" value="Go back to step 3" onClick="javascript:backPage()">
1078: </td>
1079: <td align='right'>
1080: <input type="button" name="nextpage" value="Continue to step 5" onClick="javascript:nextPage()">
1081: </td>
1082: </tr>
1083: </table>
1084: </td>
1085: </tr>
1086: </table>
1087: </td>
1088: </tr>
1089: </table>
1090: </form>
1091: |);
1092: }
1093:
1094: # ---------------------------------------------------------------- Final Display
1095: sub final_display {
1096: my ($r,$uname,$fn,$page,$textref) = @_;
1.6 ! albertel 1097: my $qnumformat = $env{'form.qnumformat'};
! 1098: my $blocks = $env{'form.blocks'};
! 1099: my $newdir = $env{'form.newdir'};
1.1 raeburn 1100: my $linkdir = $newdir;
1101: if ($linkdir =~ m#^/home/$uname/public_html/(.+)$#) {
1102: $linkdir = '/priv/'.$uname.'/'.$1;
1103: }
1104: my $question_id = '';
1105: my @question_title = ();
1106: my @question_status = ();
1107: my @qtype = ();
1108: my @start = ();
1109: my @nums = ();
1110: my @end = ();
1111: my @foilformats = ();
1112: my @ansrtypes = ();
1113: my %multparts = ();
1114: my $numitems = 0;
1115: for (my $i=0; $i<$blocks; $i++) {
1.6 ! albertel 1116: $start[$i] = $env{"form.start_$i"};
! 1117: $end[$i] = $env{"form.end_$i"};
1.1 raeburn 1118: if (($end[$i] - $start[$i]) >= 0) {
1119: $nums[$i] = $end[$i] - $start[$i]+1;
1120: } else {
1121: $nums[$i] = 0;
1122: }
1.6 ! albertel 1123: $qtype[$i] = $env{"form.qtype_$i"};
1.1 raeburn 1124: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.6 ! albertel 1125: $foilformats[$i] = $env{"form.foilformat_$i"};
1.1 raeburn 1126: } else {
1127: $foilformats[$i] = '';
1128: }
1129: if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
1.6 ! albertel 1130: $ansrtypes[$i] = $env{"form.ansr_$i"};
1.1 raeburn 1131: }
1132: $numitems += $nums[$i];
1133: }
1134:
1135: my @bgcolors = ('#ffffff','#eeeeee');
1136:
1137: my $import = join/'\s'/,@{$textref};
1138: my %answers = ();
1139: my @items = &file_split(\@start,\@end,\@nums,$qnumformat,\@foilformats,$textref,\%multparts,$numitems,\@qtype,$blocks);
1140:
1141: # Converting MC and MA answer to number, and splitting answers for FIB, and ordering for Ord.
1142: 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");
1143: 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");
1144: my %patterns = (
1145: comma => ',',
1146: space => '\s+',
1147: line => '[\r\n\f]+',
1148: tab => '\t+',
1149: );
1150: for (my $i=0; $i<$blocks; $i++) {
1151: if ($nums[$i] > 0) {
1152: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "Ord")) {
1153: for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) {
1154: @{$answers{$k}} = ();
1155: if ($qtype[$i] eq "MC") {
1.4 raeburn 1156: $items[$k] =~ tr/A-Z/a-z/;
1.1 raeburn 1157: $items[$k] =~ s/\W//g;
1.5 raeburn 1158: 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 1159: for (my $j=0; $j<@alphabet; $j++) {
1160: if ($alphabet[$j] eq $items[$k]) {
1161: push @{$answers{$k}}, $j;
1162: last;
1163: }
1164: }
1.5 raeburn 1165: } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
1.1 raeburn 1166: for (my $j=0; $j<@romans; $j++) {
1167: if ($romans[$j] eq $items[$k]) {
1168: push @{$answers{$k}}, $j;
1169: last;
1170: }
1171: }
1172: }
1173: } elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1.4 raeburn 1174: $items[$k] =~ tr/A-Z/a-z/;
1.1 raeburn 1175: my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k];
1176: foreach my $correct (@corrects) {
1177: $correct =~s/\W//g;
1178: if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {
1179: for (my $j=0; $j<@alphabet; $j++) {
1180: if ($alphabet[$j] eq $correct) {
1181: push @{$answers{$k}}, $j;
1182: last;
1183: }
1184: }
1.5 raeburn 1185: } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
1.1 raeburn 1186: for (my $j=0; $j<@romans; $j++) {
1187: if ($romans[$j] eq $correct) {
1188: push @{$answers{$k}}, $j;
1189: last;
1190: }
1191: }
1192: }
1193: }
1194: } elsif ($qtype[$i] eq "FIB") {
1195: @{$answers{$k}} = split/$patterns{$ansrtypes[$i]}/,$items[$k];
1196: for (my $j=0; $j<@{$answers{$k}}; $j++) {
1197: $answers{$k}[$j] =~ s/^\s+//;
1198: $answers{$k}[$j] =~ s/\s+$//;
1199: }
1200: }
1201: }
1202: }
1203: }
1204: }
1205: my $pooltarget = '';
1206: my $pooldesc = '';
1207: my @newquestions = ();
1208: my $numquestions = 0;
1209: my %qtype = ();
1210: my %qtext = ();
1211: my %qflag = ();
1212:
1213: $r->print(<<"END_OF_BLOCK");
1214: <form name="verify" method="post">
1215: <table border='0' cellspacing='0' cellpadding='0' width="100%">
1216: <tr>
1217: <td colspan='2' align='left'>
1218: </td>
1219: </tr>
1220: <tr bgcolor='#ccddaa'>
1221: <td align='top'>
1222: </td>
1223: <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
1224: <font size='+1' face='arial,helvetica,sans-serif'> <b>Result of conversion of tesbank questions to LON-CAPA problems.</b></font>
1225: </td>
1226: </tr>
1227: <tr>
1228: <td colspan='2'> </td>
1229: </tr>
1230: END_OF_BLOCK
1231: if ($newdir ne "") {
1232: my @qn_file = ();
1233: my $qcount = 0;
1234: for (my $i=0; $i<$blocks; $i++) {
1235: if ($nums[$i] > 0) {
1236: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "Ord")) {
1237: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1238: my $answer = $j + $numitems;
1239: my $numans = scalar(@{$answers{$answer}});
1240: my $foilcount = 0;
1241: if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
1242: $foilcount = @{$multparts{$j}};
1243: $foilcount --;
1244: }
1245: $qn_file[$qcount] = &create_mcq($newdir,\@{$multparts{$j}},\@{$answers{$answer}},$qtype[$i],$j);
1246: $qcount ++;
1247: push @newquestions, $question_id;
1248: }
1249: } elsif ($qtype[$i] eq "TF") {
1250: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1251: my $answer = $j + $numitems;
1252: $items[$answer] =~ s/^\s+//;
1253: $items[$answer] =~ s/\s+$//;
1254: $items[$answer] =~ s/\W//g;
1255: $items[$answer] =~ tr/A-Z/a-z/;
1256: my $answer_id = '';
1257: if ($ansrtypes[$i] eq 'word' ) {
1258: if ($items[$answer] =~ m/true/) {
1259: $answer_id = 0;
1260: } else {
1261: $answer_id = 1;
1262: }
1263: } elsif ($ansrtypes[$i] eq 'lett') {
1264: if ($items[$answer] =~ m/^t/) {
1265: $answer_id = 0;
1266: } else {
1267: $answer_id = 1;
1268: }
1269: }
1270: $qn_file[$qcount] = create_ess($newdir,$answer_id,$items[$j],$items[$answer],$qtype[$i],$j);
1271: push @newquestions, $question_id;
1272: $qcount ++;
1273: }
1274: } elsif ($qtype[$i] eq "Ess") {
1275: for (my $j=$start[$i]-1; $j<$end[$i]; $j++) {
1276: my $answer = $j + $numitems;
1277: my $answer_id = '';
1278: $qn_file[$qcount] = create_ess($newdir,$answer_id,$items[$j],$items[$answer],$qtype[$i],$j);
1279: push @newquestions, $question_id;
1280: $qcount ++;
1281: }
1282: }
1283: }
1284: }
1285: $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:
1286: <ul>|);
1287: for (my $i=0; $i<@qn_file; $i++) {
1288: my $display = $i+1;
1289: $r->print(qq|
1290: <li><b><a href="$linkdir/$qn_file[$i]">Problem $display file</a></b></li>
1291: |);
1292: }
1293: $r->print(qq|
1294: </ul></font></td></tr>
1295: <tr><td> </td>
1296: <td><font face='arial,helvetica,sans-serif'>The problems must be published before they can be used in a course.</font></td>
1297: |);
1298: } else {
1299: $r->print(qq|
1300: <tr>
1301: <td> </td>
1302: <td><font face='arial,helvetica,sans-serif'>No destination file was selected or created, so import of your questions could not proceed.
1303: Please return to the previous page and select a valid file into which to import the questions. </font>
1304: <input type="hidden" name="go" value="">
1305: <input type="hidden" name="page" value="$page">
1306: <input type="hidden" name="uploaduname" value="$uname">
1307: <input type="hidden" name="filename" value="$fn">
1308: <input type='hidden' name="page" value="$page">
1309: <input type="hidden" name="phase" value="three">
1310: <input type="hidden" name="qnumformat" value="$qnumformat">
1311: <input type="hidden" name="newdir" value="$newdir">
1312: |);
1313: for (my $i=0; $i<$blocks; $i++) {
1314: $r->print(qq|
1315: <input type="hidden" name="start_$i" value="$start[$i]">
1316: <input type="hidden" name="end_$i" value="$end[$i]">
1317: <input type="hidden" name="qtype_$i" value="$qtype[$i]">
1318: <input type="hidden" name="foilformat_$i" value="$foilformats[$i]">
1319: <input type="hidden" name="ansr_$i" value="$ansrtypes[$i]">
1320: |);
1321: }
1322: $r->print(<<"END_OF_FAIL");
1323: </td>
1324: </tr>
1325: <tr>
1326: <td colspan='2'>
1327: <table border='0' width='100%'>
1328: <tr>
1329: <td align='right'>
1330: <input type="button" name="backpage" value="Return to step 3" onClick="javascript:backPage()">
1331: </td>
1332: </tr>
1333: </table>
1334: </td>
1335: </tr>
1336: </table>
1337: </td>
1338: </tr>
1339: </table>
1340: </td>
1341: </tr>
1342: </table>
1343: </form>
1344: </body>
1345: </html>
1346: END_OF_FAIL
1347: return;
1348: }
1349: $r->print(<<"END_OF_BODY");
1350: </table>
1351: </td>
1352: </tr>
1353: </table>
1354: </td>
1355: </tr>
1356: <tr>
1357: <td colspan='2'>
1358: <input type="hidden" name="go" value="">
1359: <input type="hidden" name="page" value="$page">
1360: <input type="hidden" name="uploaduname" value="$uname">
1361: <input type="hidden" name="filename" value="$fn">
1362: <input type='hidden' name="page" value="$page">
1363: <input type="hidden" name="phase" value="one">
1364: <input type="hidden" name="qnumformat" value="$qnumformat">
1365: <input type="hidden" name="newdir" value="$newdir">
1366: </td>
1367: </tr>
1368: <tr>
1369: <td colspan='2'>
1370: <table border='0' width='100%'>
1371: <tr>
1372: <td align='left'>
1373: <input type='button' name='backtostart' value='Back to start page' onClick='javascript:backtoStart()'>
1374: </td>
1375: </tr>
1376: </table>
1377: </td>
1378: </tr>
1379: </table>
1380: </td>
1381: </tr>
1382: </table>
1383: </td>
1384: </tr>
1385: </table>
1386: </form>
1387: END_OF_BODY
1388: }
1389:
1390: sub question_count {
1391: my ($qnumformat,$textref) = @_;
1392: my $text_in = join "\n", @{$textref};
1393: $text_in = "\n ".$text_in;
1394: my $qpattern ='';
1395: if ($qnumformat eq "period") {
1396: $qpattern = '\d{1,}\.';
1397: } elsif ($qnumformat eq "paren") {
1398: $qpattern = '\(\d{1,}\)';
1399: } elsif ($qnumformat eq "number") {
1400: $qpattern = '\d{1,}';
1401: } elsif ($qnumformat eq "leadparen") {
1402: $qpattern = '\(\d{1,}';
1403: } elsif ($qnumformat eq "trailparen") {
1404: $qpattern = '\d{1,}\)';
1405: }
1406: my @questions = split/[\r\n\f]+\s?$qpattern\s?/,$text_in;
1407: my $qcount = scalar(@questions);
1408: $qcount = $qcount/2;
1409: $qcount = int($qcount);
1410: return $qcount;
1411: }
1412:
1413: sub file_split {
1414: my ($startsref,$endsref,$numsref,$qnumformat,$foilsref,$textref,$multpartsref,$numitems,$qtyperef,$blocks) = @_;
1415: my $text_in = join "\n", @{$textref};
1416: $text_in = "\n ".$text_in;
1417: my $dignum = length($numitems);
1418: my $numpat;
1419: if ($dignum > 1) {
1420: $numpat = ','.$dignum.'}';
1421: } else {
1422: $numpat = '}';
1423: }
1424: my $qpattern ='';
1425: if ($qnumformat eq "period") {
1426: $qpattern = '\d{1'.$numpat.'\.';
1427: } elsif ($qnumformat eq "paren") {
1428: $qpattern = '\(\d{1'.$numpat.'\)';
1429: } elsif ($qnumformat eq "number") {
1430: $qpattern = '\d{1'.$numpat;
1431: } elsif ($qnumformat eq "leadparen") {
1432: $qpattern = '\(\d{1'.$numpat;
1433: } elsif ($qnumformat eq "trailparen") {
1434: $qpattern = '\d{1'.$numpat.'\)';
1435: }
1.5 raeburn 1436: my @questions = split/[\r\n\f]+\s*$qpattern\s*/,$text_in;
1.1 raeburn 1437: # my @questions = split/\n\s\d{1,3}\.\s/,$text_in;
1438: shift @questions;
1439: my %multparts = ();
1440: for (my $i=0; $i<$blocks; $i++) {
1441: if (${$numsref}[$i] > 0) {
1442: if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA")) {
1443: my $splitstr = '';
1444: if (${$foilsref}[$i] eq "lcperiod") {
1445: $splitstr = '[a-z]\.';
1446: } elsif (${$foilsref}[$i] eq "lcparen") {
1447: $splitstr = '\([a-z]\)';
1.5 raeburn 1448: } elsif (${$foilsref}[$i] eq "lconeparen") {
1449: $splitstr = '[a-z]\)';
1450: } elsif (${$foilsref}[$i] eq "lcdotparen") {
1451: $splitstr = '[a-z]\.\)';
1.1 raeburn 1452: } elsif (${$foilsref}[$i] eq "ucperiod") {
1453: $splitstr = '[A-Z]\.';
1454: } elsif (${$foilsref}[$i] eq "ucparen") {
1455: $splitstr = '\([A-Z]\)';
1.5 raeburn 1456: } elsif (${$foilsref}[$i] eq "uconeparen") {
1457: $splitstr = '[A-Z]\)';
1458: } elsif (${$foilsref}[$i] eq "ucdotparen") {
1459: $splitstr = '[A-Z]\.\)';
1.1 raeburn 1460: } elsif (${$foilsref}[$i] eq "romperiod") {
1461: $splitstr = '[ivx]+\.';
1462: } elsif (${$foilsref}[$i] eq "romparen") {
1463: $splitstr = '\([ivx]+\)';
1.5 raeburn 1464: } elsif (${$foilsref}[$i] eq "romoneparen") {
1465: $splitstr = '[ivx]+\)';
1466: } elsif (${$foilsref}[$i] eq "romdotparen") {
1467: $splitstr = '[ivx]+\.\)';
1.1 raeburn 1468: }
1469: for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
1.5 raeburn 1470: @{$multparts{$j}} = split/[\r\n\f]+\s*$splitstr\s*/,$questions[$j];
1.1 raeburn 1471: chomp(@{$multparts{$j}});
1472: }
1473: } elsif (${$qtyperef}[$i] eq "FIB") {
1474: for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
1475: @{$multparts{$j}} = ("$questions[$j]");
1476: }
1477: }
1478: }
1479: }
1480: %{$multpartsref} = %multparts;
1481: return @questions;
1482: }
1483:
1484: # create_mcq builds an MC, MA, Ord or FIB question
1485:
1486: sub create_mcq {
1487: my ($newdir,$qstnref,$answerref,$qtype,$qnum) = @_;
1488: $qnum ++;
1489: if (length($qnum) == 1) {
1490: $qnum = "00".$qnum;
1491: } elsif (length($qnum) == 2) {
1492: $qnum = "0".$qnum;
1493: }
1494: my $qstn = ${$qstnref}[0];
1495: my $numfoils = scalar(@{$qstnref}) - 1;
1496: my $datestamp = localtime;
1497: my $timestamp = time;
1498: my $libfile = 'question_'.$qnum;
1499: $libfile .= '.problem';
1500: my $numansrs = scalar(@{$answerref});
1501: my $output = qq|<problem>
1502: <startouttext />$qstn<endouttext />
1503: |;
1504:
1505: if ($qtype eq "MA") {
1506: $output .= qq|
1507: <optionresponse max="$numfoils" randomize="yes">
1508: <foilgroup options="('True','False')">
1509: |;
1510: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1511: $output .= " <foil name=\"foil".$k."\" value=\"";
1512: if (grep/^$k$/,@{$answerref}) {
1513: $output .= "True\" location=\"random\"";
1514: } else {
1515: $output .= "False\" location=\"random\"";
1516: }
1517: $output .= "\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1518: }
1519: chomp($output);
1520: $output .= qq|
1521: </foilgroup>
1522: </optionresponse>
1523: </problem>
1524: |;
1525: }
1526: if ($qtype eq "MC") {
1527: $output .= qq|
1528: <radiobuttonresponse max="$numfoils" randomize="yes">
1529: <foilgroup>
1530: |;
1531: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1532: $output .= " <foil name=\"foil".$k."\" value=\"";
1533: if (grep/^$k$/,@{$answerref}) {
1534: $output .= "true\" location=\"";
1535: } else {
1536: $output .= "false\" location=\"";
1537: }
1538: if (lc (${$qstnref}[$k+1]) =~ m/^\s?([Aa]ll)|([Nn]one)\sof\sthe\sabove\.?/) {
1539: $output .= "bottom\"";
1540: } else {
1541: $output .= "random\"";
1542: }
1543: $output .= "\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1544: }
1545: chomp($output);
1546: $output .= qq|
1547: </foilgroup>
1548: </radiobuttonresponse>
1549: </problem>
1550: |;
1551: }
1552:
1553: if ($qtype eq "Ord") {
1554: $output .= qq|
1555: <rankresponse max="$numfoils" randomize="yes">
1556: <foilgroup>
1557: |;
1558: for (my $k=0; $k<@{$qstnref}-1; $k++) {
1559: $output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$answerref[$k]."\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
1560: }
1561: chomp($output);
1562: $output .= qq|
1563: </foilgroup>
1564: </rankresponse>
1565: </problem>
1566: |;
1567: }
1568:
1569: if ($qtype eq "FIB") {
1570: my $numerical = 1;
1571: for (my $i=0; $i<@{$answerref}; $i++) {
1572: if (${$answerref}[$i] =~ m/([^\d\.]|\.\.)/) {
1573: $numerical = 0;
1574: }
1575: }
1576: if ($numerical) {
1577: my $numans;
1578: my $tol;
1579: if (@{$answerref} == 1) {
1580: $tol = 5;
1581: $numans = $$answerref[0];
1582: } else {
1.2 raeburn 1583: my $min = $$answerref[0];
1584: my $max = $$answerref[0];
1585: for (my $i=1; $i<@{$answerref}; $i++) {
1586: if ($$answerref[$i]<=$min) {
1.1 raeburn 1587: $min = $$answerref[$i];
1.2 raeburn 1588: } elsif ($$answerref[$i] >= $max) {
1.1 raeburn 1589: $max = $$answerref[$i];
1590: }
1591: }
1592: $numans = ($max + $min)/2;
1593: $tol = 100*($max - $min)/($numans*2);
1594: }
1595: $output .= qq|
1596: <numericalresponse answer="$numans">
1597: <responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" />
1598: <responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />
1599: <textline />
1600: </numericalresponse>
1601: </problem>
1602: |;
1603: } else {
1604: if (@{$answerref} == 1) {
1605: $output .= qq|
1606: <stringresponse answer="$$answerref[0]" type="ci">
1607: <textline>
1608: </textline>
1609: </stringresponse>
1610: </problem>
1611: |;
1612: } else {
1613: for (my $i=0; $i<@{$answerref}; $i++) {
1614: ${$answerref}[$i] =~ s/\|/\|/g;
1615: }
1616: my $regexpans = join('|',@{$answerref});
1617: $regexpans = '/('.$regexpans.')/';
1618: $output .= qq|
1619: <stringresponse answer="$regexpans" type="re">
1620: <textline>
1621: </textline>
1622: </stringresponse>
1623: </problem>
1624: |;
1625: }
1626: }
1627: }
1628: open(PROB,">$newdir/$libfile");
1629: print PROB $output;
1630: close PROB;
1631: return $libfile;
1632: }
1633:
1634: # create_ess builds an essay or True/False question
1635:
1636: sub create_ess {
1637: my ($newdir,$answer_id,$qstn,$answertxt,$qtype,$qnum) = @_;
1638: $qnum ++;
1639: if (length($qnum) == 1) {
1640: $qnum = "00".$qnum;
1641: } elsif (length($qnum) == 2) {
1642: $qnum = "0".$qnum;
1643: }
1644: my $libfile = 'question_'.$qnum;
1645: $libfile .= '.problem';
1646: my $output = qq|<problem>
1647: <startouttext />$qstn<endouttext />|;
1648:
1649: my $answer = '';
1650: my $answerlog = '';
1651: if ($qtype eq "Ess") {
1652: $output .= qq|
1653: <essayresponse>
1654: <textfield></textfield>
1655: </essayresponse>
1656: <postanswerdate>
1657: $answertxt
1658: </postanswerdate>
1659: </problem>|;
1660: } elsif ($qtype eq "TF") {
1661: $answer = $answer_id;
1662: $output .= qq|
1663: <radiobuttonresponse max="2" randomize="yes">
1664: <foilgroup>
1665: |;
1666: $output .= " <foil name=\"foil0\" value=\"true\" location=\"random\"><startouttext />";
1667: if ($answer_id) {
1668: $output .= "False";
1669: } else {
1670: $output .= "True";
1671: }
1672: $output .= "<endouttext /></foil>\n";
1673: $output .= " <foil name=\"foil1\" value=\"false\" location=\"random\"><startouttext />";
1674: if ($answer_id) {
1675: $output .= "True";
1676: } else {
1677: $output .= "False";
1678: }
1679: $output .= qq|<endouttext /></foil>
1680: </foilgroup>
1681: </radiobuttonresponse>
1682: </problem>|;
1683: }
1684: open(PROB,">$newdir/$libfile");
1685: print PROB $output;
1686: close PROB;
1687: return $libfile;
1688: }
1689:
1690: sub file_error {
1691: my ($r,$uname,$fn,$current_page);
1692: $r->print("No data here");
1693: }
1694:
1695: # ---------------------------------------------------------------- Main Handler
1696: sub handler {
1697: my $r=shift;
1698: my $uname;
1699: my $udom;
1700: my $javascript = '';
1701: my $page_name = '';
1702: my $current_page = '';
1703: my $loadentries = '';
1704: my $qcount = '';
1705: #
1706: # phase two: re-attach user
1707: #
1.6 ! albertel 1708: if ($env{'form.uploaduname'}) {
! 1709: $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
! 1710: $env{'form.filename'};
1.1 raeburn 1711: }
1712: ($uname,$udom)=
1.6 ! albertel 1713: &Apache::loncacc::constructaccess($env{'form.filename'},
1.1 raeburn 1714: $r->dir_config('lonDefDomain'));
1715: unless (($uname) && ($udom)) {
1716: $r->log_reason($uname.' at '.$udom.
1.6 ! albertel 1717: ' trying to publish file '.$env{'form.filename'}.
1.1 raeburn 1718: ' - not authorized',
1719: $r->filename);
1720: return HTTP_NOT_ACCEPTABLE;
1721: }
1722:
1723: my $fn;
1724: my $badfile = 0;
1.6 ! albertel 1725: if ($env{'form.filename'}) {
! 1726: $fn=$env{'form.filename'};
1.1 raeburn 1727: $fn=~s/^http\:\/\/[^\/]+\///;
1728: $fn=~s/^\///;
1729: $fn=~s/(\~|priv\/)(\w+)//;
1730: $fn=~s/\/+/\//g;
1731: } else {
1.6 ! albertel 1732: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.1 raeburn 1733: ' unspecified filename for upload', $r->filename);
1734: return HTTP_NOT_FOUND;
1735: }
1736: my $pathname = &File::Basename::dirname($fn);
1737: my $fullpath = '/priv/'.$uname.$pathname;
1738: unless ($pathname eq '/') {
1739: $fullpath .= '/';
1740: }
1741:
1742: my $dirpath = '/home/'.$uname.'/public_html';
1743:
1744: my @text = ();
1745: my $loadentries = '';
1.6 ! albertel 1746: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1747: if (-e "$dirpath$fn") {
1748: open(TESTBANK,"<$dirpath$fn");
1749: @text = <TESTBANK>;
1750: close(TESTBANK);
1751: } else {
1752: $badfile = 1;
1753: }
1754: }
1755:
1756: # ----------------------------------------------------------- Start page output
1757: &Apache::loncommon::content_type($r,'text/html');
1758: $r->send_http_header;
1759:
1.6 ! albertel 1760: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1761: $current_page = &display_control();
1762: my @PAGES = ('Welcome','Blocks','Format','Target','Confirmation');
1763: $page_name = $PAGES[$current_page];
1764:
1765: if ($page_name eq 'Blocks') {
1766: $loadentries = 'onLoad= "setElements()"';
1767: &jscript_one(\$javascript);
1768: } elsif ($page_name eq 'Format') {
1.6 ! albertel 1769: $qcount = question_count($env{'form.qnumformat'},\@text);
1.1 raeburn 1770: &jscript_two(\$javascript,$qcount);
1771: } elsif ($page_name eq 'Target') {
1.6 ! albertel 1772: if ($env{'form.go'} eq "PreviousPage") {
1.1 raeburn 1773: $loadentries = 'onLoad = "setElements()"';
1774: }
1775: &jscript_three($fullpath,\$javascript);
1776: } elsif ($page_name eq 'Confirmation') {
1777: &jscript_four(\$javascript,$fullpath);
1778: }
1779: }
1780:
1781: $r->print("<html><head><title>LON-CAPA Construction Space</title><script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n</head>");
1782:
1783: $r->print(&Apache::loncommon::bodytag('Upload testbank questions to Construction Space',undef,$loadentries));
1784:
1.6 ! albertel 1785: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1 raeburn 1786: $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
1787: &mt(' at ').$udom.'</font></h3>');
1788: }
1789:
1.6 ! albertel 1790: if ($env{'form.phase'} eq 'three') {
1.1 raeburn 1791: if ($badfile) {
1792: &file_error($r,$uname,$fn,$current_page);
1793: } else {
1794: &display_zero ($r,$uname,$fn,$current_page,$fullpath) if $page_name eq 'Welcome';
1795: &display_one ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Blocks';
1796: &display_two ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Format';
1797: &display_three ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Target';
1798: &final_display ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Confirmation';
1799: }
1.6 ! albertel 1800: } elsif ($env{'form.phase'} eq 'two') {
1.1 raeburn 1801: my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'testbank');
1802: if ($flag eq 'ok') {
1803: my $current_page = 0;
1804: &display_zero($r,$uname,$fn,$current_page,$fullpath);
1805: }
1806: } else {
1807: &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'testbank');
1808: }
1809: $r->print('</body></html>');
1810: return OK;
1811: }
1812: 1;
1813: __END__
1814:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>