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