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