Diff for /loncom/publisher/testbankimport.pm between versions 1.17 and 1.45

version 1.17, 2008/09/22 01:53:33 version 1.45, 2017/11/12 23:08:58
Line 28  package Apache::testbankimport; Line 28  package Apache::testbankimport;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http :methods);  use Apache::Constants qw(:common :http :methods);
 use Apache::loncacc;  
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonnet;  use Apache::lonnet;
 use HTML::Entities();  use HTML::Entities();
Line 81  function createWin() { Line 80  function createWin() {
     newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")      newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
     newWindow.document.open()      newWindow.document.open()
     newWindow.document.write('$start_page')      newWindow.document.write('$start_page')
     newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")      newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]' />\\n")
     newWindow.document.write("<h3>$lt{'loca'}: <tt>$webpath</tt></h3><h3>$lt{'newd'}</h3>\\n")      newWindow.document.write("<h3>$lt{'loca'}: <tt>$webpath</tt></h3><h3>$lt{'newd'}</h3>\\n")
     newWindow.document.write("<form name='fileaction' action='/adm/cfile' method='post'>\\n")      newWindow.document.write("<form name='fileaction' action='/adm/cfile' method='post'>\\n")
     newWindow.document.write("$lt{'ente'}.<br /><br />")      newWindow.document.write("$lt{'ente'}.<br /><br />")
     newWindow.document.write("<input type='hidden' name='filename' value='$webpath'>")      newWindow.document.write("<input type='hidden' name='filename' value='$webpath' />")
     newWindow.document.write("<input type='hidden' name='action' value='newdir'>")      newWindow.document.write("<input type='hidden' name='action' value='newdir' />")
     newWindow.document.write("<input type='hidden' name='callingmode' value='testbank'>")      newWindow.document.write("<input type='hidden' name='callingmode' value='testbank' />")
     newWindow.document.write("$webpath<input type='text' name='newfilename' value=''/>")      newWindow.document.write("<input type='hidden' name='inhibitmenu' value='yes' />")
     newWindow.document.write("<input type='button' value='$lt{'go'}' onClick='document.fileaction.submit();' /></form>")      newWindow.document.write("$webpath<input type='text' name='newfilename' value='' />")
       newWindow.document.write("<input type='button' value='$lt{'go'}' onclick='document.fileaction.submit();' /></form>")
     newWindow.document.write('$end_page')      newWindow.document.write('$end_page')
     newWindow.document.close()      newWindow.document.close()
     newWindow.focus()      newWindow.focus()
Line 289  function colSet(caller) { Line 289  function colSet(caller) {
     else {      else {
         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")) {          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")) {
             poolForm.elements[caller*5+4].options[0] = new Option("Select","-1",true,true)              poolForm.elements[caller*5+4].options[0] = new Option("Select","-1",true,true)
             poolForm.elements[caller*5+4].options[1] = new Option("a.","lcperiod",false,false)              poolForm.elements[caller*5+4].options[1] = new Option("a ","lcspace",false,false)
             poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false)              poolForm.elements[caller*5+4].options[2] = new Option("A ","ucspace",false,false) 
             poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false)              poolForm.elements[caller*5+4].options[3] = new Option("a.","lcperiod",false,false)
             poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false)              poolForm.elements[caller*5+4].options[4] = new Option("A.","ucperiod",false,false)
             poolForm.elements[caller*5+4].options[5] = new Option("a)","lconeparen",false,false)              poolForm.elements[caller*5+4].options[5] = new Option("(a)","lcparen",false,false)
             poolForm.elements[caller*5+4].options[6] = new Option("A)","uconeparen",false,false)              poolForm.elements[caller*5+4].options[6] = new Option("(A)","ucparen",false,false)
             poolForm.elements[caller*5+4].options[7] = new Option("a.)","lcdotparen",false,false)              poolForm.elements[caller*5+4].options[7] = new Option("a)","lconeparen",false,false)
             poolForm.elements[caller*5+4].options[8] = new Option("A.)","ucdotparen",false,false)              poolForm.elements[caller*5+4].options[8] = new Option("A)","uconeparen",false,false)
             poolForm.elements[caller*5+4].options[9] = new Option("(i)","romparen",false,false)              poolForm.elements[caller*5+4].options[9] = new Option("a.)","lcdotparen",false,false)
             poolForm.elements[caller*5+4].options[10] = new Option("i)","romoneparen",false,false)              poolForm.elements[caller*5+4].options[10] = new Option("A.)","ucdotparen",false,false)
             poolForm.elements[caller*5+4].options[11] = new Option("i.)","romdotparen",false,false)              poolForm.elements[caller*5+4].options[11] = new Option("(i)","romparen",false,false)
             poolForm.elements[caller*5+4].options[12] = new Option("i.","romperiod",false,false)              poolForm.elements[caller*5+4].options[12] = new Option("i)","romoneparen",false,false)
               poolForm.elements[caller*5+4].options[13] = new Option("i.)","romdotparen",false,false)
               poolForm.elements[caller*5+4].options[14] = new Option("i.","romperiod",false,false)
             poolForm.elements[caller*5+4].selectedIndex = 0              poolForm.elements[caller*5+4].selectedIndex = 0
         }          }
         else {          else {
Line 444  function verify() { Line 446  function verify() {
     if ($numitems > 0) {      if ($numitems > 0) {
         my $maxnum = $numitems - 1;          my $maxnum = $numitems - 1;
         my %lt = &Apache::lonlocal::texthash(          my %lt = &Apache::lonlocal::texthash(
                                               fnmb => 'File names must be unique',                                                fnmb => 'Filenames must be unique',
                                               isum => 'is used more than once',                                                isum => 'is used more than once',
                                             );                                              );
         $$jsref .= qq|          $$jsref .= qq|
Line 484  function backPage() { Line 486  function backPage() {
   
 # ---------------------------------------------------------------- Display Zero  # ---------------------------------------------------------------- Display Zero
 sub display_zero {  sub display_zero {
     my ($r,$uname,$fn,$page,$webpath) = @_;      my ($r,$fn,$page,$webpath) = @_;
     my $go_default = 'NextPage';       my $go_default = 'NextPage'; 
     if ($fn eq '') {      if ($fn eq '') {
         $r->print('<b>'.&mt('Incomplete file upload').'</b> '.&mt('Return to the [_1]construction space menu[_2] to upload a file','<a href="'.$webpath.'">','</a>'));          $r->print('<b>'.&mt('Incomplete file upload').'</b> '.&mt('Return to the [_1]Authoring Space menu[_2] to upload a file','<a href="'.$webpath.'">','</a>'));
     }      }
     $r->print(&mt('The <b>Testbank Upload</b> utility can be used by LON-CAPA authors to generate LON-CAPA problem files from a testbank file of questions/answers.').'<br />'.      $r->print(&mt('The [_1]Testbank Upload[_2] utility can be used by LON-CAPA authors to generate LON-CAPA problem files from a testbank file of questions/answers.','<b>','</b>').'<br />'.
               &mt('The following question types can be converted:').'                &mt('The following question types can be converted:').'
               <ul>                <ul>
                 <li>'.&mt('multiple choice').'</li>                  <li>'.&mt('multiple choice').'</li>
Line 508  sub display_zero { Line 510  sub display_zero {
          <li>'.&mt('Review the identified questions, choose which to convert, and (optionally) override the default filename to be used for each problem file.').'</li>            <li>'.&mt('Review the identified questions, choose which to convert, and (optionally) override the default filename to be used for each problem file.').'</li> 
          <li>'.&mt('Complete the import of questions.').'</li>           <li>'.&mt('Complete the import of questions.').'</li>
         </ol><form name="info" method="post" action="/adm/testbank">'.          </ol><form name="info" method="post" action="/adm/testbank">'.
         &topic_bar(1,&mt('Optional: create a sub-directory in which the testbank questions will be saved')).          &Apache::lonhtmlcommon::topic_bar(1,&mt('Optional: create a sub-directory in which the testbank questions will be saved')).
         &mt('By default, LON-CAPA problems generated from the testbank file will be stored in the current directory.').' '.&mt('To store them in a new sub-directory:').           &mt('By default, LON-CAPA problems generated from the testbank file will be stored in the current directory.').' '.&mt('To store them in a new sub-directory:'). 
        ' <input type="button" name="createdir" value="'.&mt('Create sub-directory').'" onClick="javascript:createWin()">'.         ' <input type="button" name="createdir" value="'.&mt('Create sub-directory').'" onclick="javascript:createWin()" />'.
        &page_footer($env{'form.newdir'},$uname,$fn,$page,$webpath).'         &page_footer($env{'form.newdir'},$fn,$page,$webpath).'
        </form>');         </form>');
 }  }
   
 # ---------------------------------------------------------------- Display One  # ---------------------------------------------------------------- Display One
   
 sub display_one {  sub display_one {
     my ($r,$uname,$fn,$page,$textref,$header) = @_;      my ($r,$fn,$page,$textref,$header) = @_;
     my %topics;      my %topics;
     $topics{2} = &mt('Select the format of the question number - e.g., 1,  1., 1), (1 or (1) - ').'&nbsp;      $topics{2} = &mt('Select the format of the question number - e.g., 1,  1., 1), (1 or (1) - ').'&nbsp;
                <select name="qnumformat">                 <select name="qnumformat">
                   <option value = "-1" selected>'.&mt('Select').'</option>                    <option value="-1" selected="selected">'.&mt('Select').'</option>
                   <option value="number">1</option>                    <option value="number">1</option>
                   <option value="period">1.</option>                    <option value="period">1.</option>
                   <option value="paren">(1)</option>                    <option value="paren">(1)</option>
Line 533  sub display_one { Line 535  sub display_one {
     $r->print('<h3>'.&mt('Identification of blocks of questions').'</h3>'."\n".      $r->print('<h3>'.&mt('Identification of blocks of questions').'</h3>'."\n".
               '<form method="post" name="display" action="/adm/testbank">'."\n".                '<form method="post" name="display" action="/adm/testbank">'."\n".
               &show_uploaded_data($textref,$header)."\n".                &show_uploaded_data($textref,$header)."\n".
               &topic_bar(2,$topics{2}).'<p>'.                &Apache::lonhtmlcommon::topic_bar(2,$topics{2}).'<p>'.
               &mt('A number in the specified format should appear at the start of each question.').'<br />'.                &mt('A number in the specified format should appear at the start of each question.').'<br />'.
               &mt('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.').'<br />'."\n".                &mt('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.').'<br />'."\n".
               &mt('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).').'<br />'."\n".                &mt('Correct answers should be numbered in the same way as the questions and should appear after [_1]all[_2] the questions (including question text and possible foils for all questions).','<b>','</b>').'<br />'."\n".
               &mt('Each numbered question must have a corresponding numbered answer, although the answer itself may be blank for essay questions.').'<br /><br />'."\n".                &mt('Each numbered question must have a corresponding numbered answer, although the answer itself may be blank for essay questions.').'<br /><br />'."\n".
               &mt('For example, you would select <b>1.</b> if your testbank file contained the following questions:').'<br /><blockquote>'.                &mt('For example, you would select [_1]1.[_2] if your testbank file contained the following questions:','<b>','</b>').'<br /><blockquote>'.
 '<pre>  '<pre>
  1. '.&mt('The capital of the USA is ...').'   1. '.&mt('The capital of the USA is ...').'
  (a) Washington D.C.   (a) Washington D.C.
Line 556  sub display_one { Line 558  sub display_one {
  3.   3.
 </pre>'.  </pre>'.
              '</blockquote></p>'.               '</blockquote></p>'.
              &topic_bar(3,$topics{3}).'<p>'.               &Apache::lonhtmlcommon::topic_bar(3,$topics{3}).'<p>'.
              &mt('For example, you would enter <b>6</b> if your testbank file contained the following sequence of questions:').'</p><blockquote>'.               &mt('For example, you would enter [_1]6[_2] if your testbank file contained the following sequence of questions:','<b>','</b>').'</p><blockquote>'.
              &mt('10 multiple choice questions').'<br />'.               &mt('10 multiple choice questions').'<br />'.
              &mt('5 essay questions').'<br />'.               &mt('5 essay questions').'<br />'.
              &mt('5 fill-in-the-blank questions').'<br />'.               &mt('5 fill-in-the-blank questions').'<br />'.
Line 565  sub display_one { Line 567  sub display_one {
              &mt('4 multiple choice questions').'<br />'.               &mt('4 multiple choice questions').'<br />'.
              &mt('3 essay questions').'</blockquote></p><p>'.               &mt('3 essay questions').'</blockquote></p><p>'.
              &mt('You will indicate the question type and the question number range for each of the blocks on the next page.').'</p><br />'.               &mt('You will indicate the question type and the question number range for each of the blocks on the next page.').'</p><br />'.
              &page_footer($env{'form.newdir'},$uname,$fn,$page).'               &page_footer($env{'form.newdir'},$fn,$page).'
  </form>');   </form>');
     return;      return;
 }  }
Line 573  sub display_one { Line 575  sub display_one {
 # ---------------------------------------------------------------- Display Two  # ---------------------------------------------------------------- Display Two
   
 sub display_two {  sub display_two {
     my ($r,$uname,$fn,$page,$textref,$header,$qcount) = @_;      my ($r,$fn,$page,$textref,$header,$qcount) = @_;
     my $blocks = $env{'form.blocks'};      my $blocks = $env{'form.blocks'};
     my $qnumformat = $env{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my @types = ("MC","MA","TF","Ess","FIB","Ord");      my @types = ("MC","MA","TF","Ess","FIB","Ord");
     my %typenames = (      my %typenames = &Apache::lonlocal::texthash(
              MC => "Multiple Choice",               MC => "Multiple Choice",
              TF => "True/False",               TF => "True/False",
              MA => "Multiple Answer",               MA => "Multiple Answer",
Line 601  sub display_two { Line 603  sub display_two {
     my $steptitle = &mt('Information about question types and formats in each block.');      my $steptitle = &mt('Information about question types and formats in each block.');
     $r->print('<h3>'.&mt('Classification of blocks').'</h3>'.      $r->print('<h3>'.&mt('Classification of blocks').'</h3>'.
               '<form method="post" name="display" action="/adm/testbank"><p>'.                '<form method="post" name="display" action="/adm/testbank"><p>'.
               &mt('You indicated that <b>all</b> questions (and the corresponding answer(s) for each question) begin with a number in the following format: [_1].','<b>'.$qnumtypes{$qnumformat}.'</b>').'</p><p>'.                &mt('You indicated that [_1]all[_2] questions (and the corresponding answer(s) for each question) begin with a number in the following format: [_3].','<b>','</b>','<b>'.$qnumtypes{$qnumformat}.'</b>').'</p><p>'.
               &mt('A total of <b>[quant,_1,question]</b> and <b>[quant,_2,answer]</b> were found in the file you uploaded.',$qcount,$qcount).' '.                &mt('A total of [_1][quant,_3,question][_2] and [_1][quant,_4,answer][_2] were found in the file you uploaded.','<b>','</b>',$qcount,$qcount).' '.
               &mt('If this total does not match the number you expect, examine your original testbank file to verify that each question <i>and</i> each answer begins with a number in the specified format.').' '.                &mt('If this total does not match the number you expect, examine your original testbank file to verify that each question [_1]and[_2] each answer begins with a number in the specified format.','<i>','</i>').' '.
               &mt('If necessary use an editor to edit your testbank file of questions, and click "Previous Page" on this page and the "Exit Now" on the preceding page, so you can upload your file again.').'</p><p>'.                &mt('If necessary use an editor to edit your testbank file of questions, and click "Previous Page" on this page and the "Exit Now" on the preceding page, so you can upload your file again.').'</p><p>'.
               &mt('You also indicated that the <b>[quant,_1,question]</b> can be divided into <b>[quant,_2,block]</b> of questions of a particular question type.',$qcount,$blocks).'</p><p>'.                &mt('You also indicated that the [_1][quant,_3,question][_2] can be divided into [_1][quant,_4,block][_2] of questions of a particular question type.','<b>','</b>',$qcount,$blocks).'</p><p>'.
               &mt('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.').'</p>'.                &mt('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.').'</p>'.
               &show_uploaded_data($textref,$header).                &show_uploaded_data($textref,$header).
               &topic_bar(4,$steptitle).'<p>'.                &Apache::lonhtmlcommon::topic_bar(4,$steptitle).'<p>'.
               &mt('For <i>each</i> of the [_1] question blocks, 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.','<b>'.$blocks.'</b>').' '.                &mt('For [_1]each[_2] of the [_3] question blocks, 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.','<i>','</i>','<b>'.$blocks.'</b>').' '.
               &mt('If required, provide additional information about foil formats and answer formats for the question types you select.').'</p><p>'.                &mt('If required, provide additional information about foil formats and answer formats for the question types you select.').'</p><p>'.
               &Apache::loncommon::start_data_table().                &Apache::loncommon::start_data_table().
               &Apache::loncommon::start_data_table_header_row().                &Apache::loncommon::start_data_table_header_row().
Line 625  sub display_two { Line 627  sub display_two {
         $r->print(&Apache::loncommon::start_data_table_row().          $r->print(&Apache::loncommon::start_data_table_row().
                  '<td valign="top">&nbsp;'.$iter.'&nbsp;</td>'."\n".                   '<td valign="top">&nbsp;'.$iter.'&nbsp;</td>'."\n".
                  '<td valign="top">&nbsp;<input type="text" name="start_'.$i.'" value="'.$bl1st.'" size="5" />&nbsp;</td>'."\n".                   '<td valign="top">&nbsp;<input type="text" name="start_'.$i.'" value="'.$bl1st.'" size="5" />&nbsp;</td>'."\n".
                  '<td valign="top">&nbsp;<input type="text" name="end_'.$i.'" value="'.$bl1end.'" size="5">&nbsp;</td>'."\n".                   '<td valign="top">&nbsp;<input type="text" name="end_'.$i.'" value="'.$bl1end.'" size="5" />&nbsp;</td>'."\n".
                  '<td valign="top">                   '<td valign="top">
    <select name="qtype_'.$i.'" onChange="colSet('.$i.')">     <select name="qtype_'.$i.'" onchange="colSet('.$i.')">
     <option value= "-1" selected>'.&mt('Select').'</option>'."\n");      <option value="-1" selected="selected">'.&mt('Select').'</option>'."\n");
         foreach my $qtype (@types) {          foreach my $qtype (@types) {
             $r->print('<option value="'.$qtype.'">'.$typenames{$qtype}.'</option>'."\n");              $r->print('<option value="'.$qtype.'">'.$typenames{$qtype}.'</option>'."\n");
         }          }
Line 647  sub display_two { Line 649  sub display_two {
                      &Apache::loncommon::end_data_table_row());                        &Apache::loncommon::end_data_table_row()); 
     }      }
     $r->print(&Apache::loncommon::end_data_table().'</p><ul><li>'.      $r->print(&Apache::loncommon::end_data_table().'</p><ul><li>'.
               &mt('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.').'</li><li>'.                &mt('For [_1]multiple choice[_2], [_1]multiple correct answer[_2] and [_1]ranking[_2] type questions, you must use the [_3]Foil format[_4] 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.','<i>','</i>','<b>','</b>').'</li><li>'.
              &mt('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:[_1] you would choose "comma", or if they were listed as:[_2] you would choose "new line".','<blockquote><pre>28. (a),(d),(e)</pre></blockquote>','<blockquote><pre>               &mt('For [_1]multiple correct answer[_2] and [_1]fill-in-the-blank[_2] questions with more than one correct answer you must use the [_3]Answer format[_4] column to choose the separator used between the answers, e.g., if the correct answers for question 28. were listed as:[_5] you would choose "comma", or if they were listed as:[_6] you would choose "new line".','<i>','</i>','<b>','</b>','<blockquote><pre>28. (a),(d),(e)</pre></blockquote>','<blockquote><pre>
 28. (a)  28. (a)
     (d)      (d)
     (e)      (e)
 </pre></blockquote>').'</li><li>'.  </pre></blockquote>').'</li><li>'.
              &mt('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.).').'</li><li>'.               &mt('For [_1]true/false[_2] questions you must use the [_3]Answer format[_4] 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.).','<i>','</i>','<b>','</b>').'</li><li>'.
             &mt('For <i>ranking</i> questions you must use the <b>Answer format</b> column to choose the separator used between the (ranked) answers.').'</li></ul>              &mt('For [_1]ranking[_2] questions you must use the [_3]Answer format[_4] column to choose the separator used between the (ranked) answers.','<i>','</i>','<b>','</b>').'</li></ul>
 <input type="hidden" name="blocks" value="'.$blocks.'" />  <input type="hidden" name="blocks" value="'.$blocks.'" />
 <input type="hidden" name="qnumformat" value="'.$qnumformat.'" />'.  <input type="hidden" name="qnumformat" value="'.$qnumformat.'" />'.
            &page_footer($env{'form.newdir'},$uname,$fn,$page).'             &page_footer($env{'form.newdir'},$fn,$page).'
 </form>');  </form>');
     return;      return;
 }  }
   
 # ---------------------------------------------------------------- Display Three  # ---------------------------------------------------------------- Display Three
 sub display_three {  sub display_three {
     my ($r,$uname,$fn,$page,$textref,$res,$header,$urlpath,$qcount) = @_;      my ($r,$fn,$page,$textref,$res,$header,$webpath,$qcount) = @_;
     my $qnumformat = $env{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my $filename = $env{'form.filename'};      my $filename = $env{'form.filename'};
     my $source = $env{'form.go'};      my $source = $env{'form.go'};
Line 681  sub display_three { Line 683  sub display_three {
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
                                           crt  => 'Create?',                                            crt  => 'Create?',
                                           typ  => 'Type',                                            typ  => 'Type',
                                           fnam => 'File Name',                                            fnam => 'Filename',
                                           ques => 'Question',                                            ques => 'Question',
                                           answ => 'Answer',                                            answ => 'Answer',
                                           chka => 'check all',                                            chka => 'check all',
Line 714  sub display_three { Line 716  sub display_three {
         if ($header ne '') {          if ($header ne '') {
             $showheader = &HTML::Entities::decode($header);              $showheader = &HTML::Entities::decode($header);
             if ($res eq 'text/html') {              if ($res eq 'text/html') {
                 $showheader = &build_image_url($urlpath,$showheader);                  $showheader = &build_image_url($webpath,$showheader);
             }              }
         }          }
     }      }
     $r->print('<h3>'.&mt('Review and selection of problems to convert').'</h3>'."\n".      $r->print('<h3>'.&mt('Review and selection of problems to convert').'</h3>'."\n".
               '<form name="dataForm" method="post" action="/adm/testbank">'."\n".                '<form name="dataForm" method="post" action="/adm/testbank">'."\n".
               &mt('Based on your previous responses your data have been split into a total of [quant,_1,question].',$numitems).                &mt('Based on your previous responses your data have been split into a total of [quant,_1,question].',$numitems).
               &topic_bar(5,&mt('Choose which problems to convert and names to use for individual problem files')));                &Apache::lonhtmlcommon::topic_bar(5,&mt('Choose which problems to convert and names to use for individual problem files')));
               if ($showheader) {                if ($showheader) {
                   $r->print($showheader.'<br />');                    $r->print($showheader.'<br />');
               }                }
Line 763  sub display_three { Line 765  sub display_three {
                                 if (($res eq 'application/rtf') || ($res eq 'text/html')) {                                  if (($res eq 'application/rtf') || ($res eq 'text/html')) {
                                     $showqn = &HTML::Entities::decode($showqn);                                      $showqn = &HTML::Entities::decode($showqn);
                                     if ($res eq 'text/html') {                                      if ($res eq 'text/html') {
                                         $showqn = &build_image_url($urlpath,$showqn);                                          $showqn = &build_image_url($webpath,$showqn);
                                     }                                      }
                                 }                                  }
                                 $r->print(&Apache::loncommon::start_data_table_row().                                  $r->print(&Apache::loncommon::start_data_table_row().
                                           '<td valign="top">'.$qnum.'.</td>'."\n".                                            '<td valign="top">'.$qnum.'.</td>'."\n".
                                           '<td valign="top"><input name="createprob" type="checkbox" "checked="checked" value="'.$j.'" /></td>'."\n".                                            '<td valign="top"><input name="createprob" type="checkbox" checked="checked" value="'.$j.'" /></td>'."\n".
                                           '<td valign="top"><b>'.$qtype[$i].'</b></td>'."\n".                                            '<td valign="top"><b>'.$qtype[$i].'</b></td>'."\n".
                                           '<td valign="top"><input type="textbox" name="probfile_'.$j.'" value="'.$libfile.'" size="20" /></td>'.                                            '<td valign="top"><input type="textbox" name="probfile_'.$j.'" value="'.$libfile.'" size="20" /></td>'.
                                           '<td valign="top">'.$showqn.'<br /><br />'."\n");                                            '<td valign="top">'.$showqn.'<br /><br />'."\n");
                             } else {                              } else {
                                 my $foiltag = '';                                  my $foiltag = '';
                                 if ($foilformats[$i] eq "lcperiod") {                                  if ($foilformats[$i] eq "lcspace") {
                                       $foiltag = $alphabet->[$k-1].' ';
                                   } elsif ($foilformats[$i] eq "ucspace") {
                                       $foiltag = $alphabet->[$k-1].' ';
                                       $foiltag =~ tr/a-z/A-Z/;
                                   } elsif ($foilformats[$i] eq "lcperiod") {
                                     $foiltag = $alphabet->[$k-1].'.';                                       $foiltag = $alphabet->[$k-1].'.'; 
                                 } elsif ($foilformats[$i] eq "lcparen") {                                  } elsif ($foilformats[$i] eq "lcparen") {
                                     $foiltag = '('.$alphabet->[$k-1].')';                                      $foiltag = '('.$alphabet->[$k-1].')';
Line 807  sub display_three { Line 814  sub display_three {
                                 if ($res eq 'application/rtf' || $res eq 'text/html') {                                  if ($res eq 'application/rtf' || $res eq 'text/html') {
                                     $showfoil = &HTML::Entities::decode($showfoil);                                      $showfoil = &HTML::Entities::decode($showfoil);
                                     if ($res eq 'text/html') {                                      if ($res eq 'text/html') {
                                         $showfoil = &build_image_url($urlpath,$showfoil);                                          $showfoil = &build_image_url($webpath,$showfoil);
                                     }                                      }
                                 }                                   } 
                                 $r->print("$foiltag $showfoil<br />\n");                                  $r->print("$foiltag $showfoil<br />\n");
Line 829  sub display_three { Line 836  sub display_three {
                         }                          }
                         $r->print(&Apache::loncommon::start_data_table_row().                          $r->print(&Apache::loncommon::start_data_table_row().
                                   '<td valign="top">'.$qnum.'</td>'."\n".                                    '<td valign="top">'.$qnum.'</td>'."\n".
                                   '<td valign="top"><input name="createprob" type="checkbox" "checked="checked" value="'.$j.'" /></td>'."\n".                                    '<td valign="top"><input name="createprob" type="checkbox" checked="checked" value="'.$j.'" /></td>'."\n".
                                   '<td valign="top"><b>'.$qtype[$i].'</b></td>'."\n".                                    '<td valign="top"><b>'.$qtype[$i].'</b></td>'."\n".
                                   '<td valign="top"><input type="textbox" name="probfile_'.$j.'" value="'.$libfile.'" size="20" /></td>'."\n".                                    '<td valign="top"><input type="textbox" name="probfile_'.$j.'" value="'.$libfile.'" size="20" /></td>'."\n".
                                   '<td valign="top">'.$items->[$j].'</td>'."\n".                                    '<td valign="top">'.$items->[$j].'</td>'."\n".
Line 858  sub display_three { Line 865  sub display_three {
           <input type="hidden" name="ansr_'.$i.'" value="'.$ansrtypes[$i].'" />');            <input type="hidden" name="ansr_'.$i.'" value="'.$ansrtypes[$i].'" />');
         }          }
     }      }
     $r->print('</p>'.&page_footer($env{'form.newdir'},$uname,$fn,$page).'      $r->print('</p>'.&page_footer($env{'form.newdir'},$fn,$page).'
               </form>');                </form>');
 }  }
   
 # ---------------------------------------------------------------- Final Display  # ---------------------------------------------------------------- Final Display
 sub final_display {  sub final_display {
     my ($r,$uname,$fn,$page,$textref,$res,$header,$css,$js,$webpath,$dirpath,$subdir) = @_;      my ($r,$fn,$page,$textref,$res,$header,$css,$js,$webpath,$dirpath,$subdir) = @_;
     my $qnumformat = $env{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my $blocks = $env{'form.blocks'};      my $blocks = $env{'form.blocks'};
     my $question_id = '';      my $question_id = '';
Line 924  sub final_display { Line 931  sub final_display {
                         $items->[$k] =~ tr/A-Z/a-z/;                          $items->[$k] =~ tr/A-Z/a-z/;
                         $items->[$k] =~ s/<\/?[^>]+>//g;                          $items->[$k] =~ s/<\/?[^>]+>//g;
                         $items->[$k] =~ s/\W//g;                          $items->[$k] =~ s/\W//g;
                         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") {                          if ($foilformats[$i] eq "lcspace" || $foilformats[$i] eq "ucspace" || $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") {
                             for (my $j=0; $j<@{$alphabet}; $j++) {                              for (my $j=0; $j<@{$alphabet}; $j++) {
                                 if ($alphabet->[$j] eq $items->[$k]) {                                  if ($alphabet->[$j] eq $items->[$k]) {
                                     push @{$answers{$qnum}}, $j;                                      push @{$answers{$qnum}}, $j;
Line 957  sub final_display { Line 964  sub final_display {
                             } else {                              } else {
                                 $correct =~s/\W//g;                                  $correct =~s/\W//g;
                             }                              }
                             if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {                              if ($foilformats[$i] eq "lcspace" || $foilformats[$i] eq "ucspace" || $foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {
                                 if (($qtype[$i] eq "Ord") && (@tied > 0)) {                                  if (($qtype[$i] eq "Ord") && (@tied > 0)) {
                                     my @ties;                                      my @ties;
                                     foreach my $tie (@tied) {                                      foreach my $tie (@tied) {
Line 1032  sub final_display { Line 1039  sub final_display {
     for (my $i=0; $i<$numitems; $i++) {      for (my $i=0; $i<$numitems; $i++) {
         $r->print('<input type="hidden" name="probfile_'.$i.'" value="'.$env{'form.probfile_'.$i}.'" />'."\n");          $r->print('<input type="hidden" name="probfile_'.$i.'" value="'.$env{'form.probfile_'.$i}.'" />'."\n");
     }      }
     $r->print(&topic_bar(6,&mt('Result of conversion of testbank questions to LON-CAPA problems')));      $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Result of conversion of testbank questions to LON-CAPA problems')));
     my $destdir = $dirpath;      my $destdir = $dirpath;
     if ($destdir ne '' && $subdir ne '') {      if ($destdir ne '' && $subdir ne '') {
         $subdir .= '/';          $subdir .= '/';
Line 1041  sub final_display { Line 1048  sub final_display {
     if (@createprobs == 0) {      if (@createprobs == 0) {
         $state = 'unchecked';          $state = 'unchecked';
         $r->print('<p>'.&mt('No questions were selected for conversion.').'</p>'.          $r->print('<p>'.&mt('No questions were selected for conversion.').'</p>'.
                   &page_footer($env{'form.newdir'},$uname,$fn,$page,$webpath,$subdir,$state).'</form>');                    &page_footer($env{'form.newdir'},$fn,$page,$webpath,$subdir,$state).'</form>');
     } elsif (($destdir ne '') && (-e $destdir)) {      } elsif (($destdir ne '') && (-e $destdir)) {
         my (@qn_file,@result,@numid);          my (@qn_file,@result,@numid);
         my $qcount = 0;          my $qcount = 0;
Line 1129  sub final_display { Line 1136  sub final_display {
             $r->print('<p>'.&mt('The following files already existed, and were not overwritten so these problems generated from the testbank have not been saved:').'<br />'.$existing.'</p>');              $r->print('<p>'.&mt('The following files already existed, and were not overwritten so these problems generated from the testbank have not been saved:').'<br />'.$existing.'</p>');
             $state = 'existing';              $state = 'existing';
         }          }
         $r->print(&page_footer($env{'form.newdir'},$uname,$fn,$page,$webpath,$subdir,$state).'</form>');          $r->print(&page_footer($env{'form.newdir'},$fn,$page,$webpath,$subdir,$state).'</form>');
     } else {      } else {
         $state = 'nodir';          $state = 'nodir';
         $r->print('<p>'.&mt('No destination directory was available so import of questions could not proceed.').'</p>'.          $r->print('<p>'.&mt('No destination directory was available so import of questions could not proceed.').'</p>'.
                   &page_footer($env{'form.newdir'},$uname,$fn,$page,$webpath,$subdir,$state).'</form>');                    &page_footer($env{'form.newdir'},$fn,$page,$webpath,$subdir,$state).'</form>');
     }      }
     return;      return;
 }  }
Line 1158  sub show_uploaded_data { Line 1165  sub show_uploaded_data {
 }  }
   
 sub page_footer {  sub page_footer {
     my ($newdir,$uname,$fn,$page,$webpath,$subdir,$state) = @_;      my ($newdir,$fn,$page,$webpath,$subdir,$state) = @_;
     my $prevval = &mt('Previous Page');      my $prevval = &mt('Previous Page');
     my $nextval = &mt('Next Page');      my $nextval = &mt('Next Page');
     my $prevclick = 'javascript:backPage();';      my $prevclick = 'javascript:backPage();';
Line 1183  sub page_footer { Line 1190  sub page_footer {
     }      }
     my $output = '      my $output = '
        <input type="hidden" name="newdir" value="'.&HTML::Entities::encode($newdir,'<>&"').'" />         <input type="hidden" name="newdir" value="'.&HTML::Entities::encode($newdir,'<>&"').'" />
        <input type="hidden" name="uploaduname" value="'.$uname.'" />  
        <input type="hidden" name="filename" value="'.$fn.'" />         <input type="hidden" name="filename" value="'.$fn.'" />
        <input type="hidden" name="page" value="'.$page.'" />         <input type="hidden" name="page" value="'.$page.'" />
        <input type="hidden" name="phase" value="three" />         <input type="hidden" name="phase" value="three" />
        <input type="hidden" name="go" value="'.$go.'" />';         <input type="hidden" name="go" value="'.$go.'" />
          <input type="hidden" name="timestamp" value="'.$env{'form.timestamp'}.'" />';
     if ($page ne '') {      if ($page ne '') {
         $output .= '          $output .= '
        <table border="0">         <table border="0">
Line 1199  sub page_footer { Line 1206  sub page_footer {
             $output .= '              $output .= '
          <td>&nbsp;</td>           <td>&nbsp;</td>
          <td>           <td>
           <input type="button" name="nextpage" value="'.$nextval.'" onclick="'.$nextclick.'">            <input type="button" name="nextpage" value="'.$nextval.'" onclick="'.$nextclick.'" />
          </td>';           </td>';
         }          }
         $output .= '    </tr>          $output .= '    </tr>
Line 1275  sub file_split { Line 1282  sub file_split {
         if (${$numsref}[$i] > 0) {          if (${$numsref}[$i] > 0) {
             if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA") || (${$qtyperef}[$i] eq "Ord")) {              if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA") || (${$qtyperef}[$i] eq "Ord")) {
                 my $splitstr = '';                  my $splitstr = '';
                 if (${$foilsref}[$i] eq "lcperiod") {                  if (${$foilsref}[$i] eq "lcspace") {
                       $splitstr = '[a-z]\s';
                   } elsif (${$foilsref}[$i] eq "ucspace") {
                       $splitstr = '[A-Z]\s';
                   } elsif (${$foilsref}[$i] eq "lcperiod") {
                     $splitstr = '[a-z]\.';                      $splitstr = '[a-z]\.';
                 } elsif (${$foilsref}[$i] eq "lcparen") {                  } elsif (${$foilsref}[$i] eq "lcparen") {
                     $splitstr = '\([a-z]\)';                      $splitstr = '\([a-z]\)';
Line 1327  sub create_mcq { Line 1338  sub create_mcq {
     my $qstn = ${$qstnref}[0];      my $qstn = ${$qstnref}[0];
     my $numfoils = scalar(@{$qstnref}) - 1;       my $numfoils = scalar(@{$qstnref}) - 1; 
     my $datestamp = localtime;      my $datestamp = localtime;
     my $timestamp = time;  
     my $numansrs = scalar(@{$answerref});      my $numansrs = scalar(@{$answerref});
     my $output = '<problem>      my $output = '<problem>';
       if ($qtype eq 'MC') {
           $output .= "\n".'<parameter name="maxtries" type="int_pos" default="2" description="Maximum Number of Tries" />';
       }
       $output .= '
  <startouttext />';   <startouttext />';
     if ($res eq 'application/rtf' || $res eq 'text/html') {      if ($res eq 'application/rtf' || $res eq 'text/html') {
         if ($header ne '') {          if ($header ne '') {
Line 1494  sub create_mcq { Line 1508  sub create_mcq {
     if (-e $destdir.$libfile) {      if (-e $destdir.$libfile) {
         $result = 'exists';          $result = 'exists';
     } else {      } else {
         if (open(PROB,">$destdir$libfile")) {          if (open(PROB,">",$destdir.$libfile)) {
             print PROB $output;              print PROB $output;
             close(PROB);              close(PROB);
             $result = 'ok';              $result = 'ok';
Line 1572  sub create_ess { Line 1586  sub create_ess {
      if (-e $destdir.$libfile) {       if (-e $destdir.$libfile) {
          $result = 'exists';           $result = 'exists';
      } else {       } else {
          if (open(PROB,">$destdir$libfile")) {           if (open(PROB,">",$destdir.$libfile)) {
              print PROB $output;               print PROB $output;
              close(PROB);               close(PROB);
                $result = 'ok';
          } else {           } else {
              $result = 'failed';               $result = 'failed';
          }           }
Line 1599  sub probfile_name { Line 1614  sub probfile_name {
 }  }
   
 sub file_error {  sub file_error {
     my ($r,$uname,$fn,$current_page,$webpath,$res) = @_;      my ($r,$fn,$current_page,$webpath,$res) = @_;
     $r->print('<p><form name="display" method="post" action="/adm/testbank">'.&mt('The file you uploaded does not appear to be in the correct format.').      $r->print('<p><form name="display" method="post" action="/adm/testbank">'.&mt('The file you uploaded does not appear to be in the correct format.').
               '</p><p>'.&mt('Extraction of questions is only possible for the following file types:').                '</p><p>'.&mt('Extraction of questions is only possible for the following file types:').
               '<ul><li>'.&mt('plain text').'</li><li>RTF</li><li>HTML</li></ul>'.                '<ul>'.
                 '<li>'.&mt('plain text').'</li>'.
                 '<li>'.&mt('RTF').'</li>'.
                 '<li>'.&mt('HTML').'</li></ul>'.
               &mt('The file type identified for the file you uploaded is [_1].','<b>'.$res.'</b>').'</p>');                &mt('The file type identified for the file you uploaded is [_1].','<b>'.$res.'</b>').'</p>');
     $r->print(&page_footer($env{'form.newdir'},$uname,$fn,$current_page,$webpath,undef,'badfile').      $r->print(&page_footer($env{'form.newdir'},$fn,$current_page,$webpath,undef,'badfile').
              '</form>');               '</form>');
     return;      return;
 }  }
   
 sub parse_datafile {  sub parse_datafile {
     my ($r,$uname,$filename,$pathname,$dirpath,$urlpath,$page_name,$subdir) = @_;      my ($r,$filename,$dirpath,$webpath,$page_name,$subdir,$timestamp) = @_;
     my ($badfile,$res,%allfiles,%codebase);      my ($badfile,$res,%allfiles,%codebase);
     my $mm = new File::MMagic;      my $mm = new File::MMagic;
     my ($text,$header,$css,$js);      my ($text,$header,$css,$js);
Line 1618  sub parse_datafile { Line 1636  sub parse_datafile {
         $res = $mm->checktype_filename($dirpath.$filename);          $res = $mm->checktype_filename($dirpath.$filename);
         if ($env{'form.phase'} eq 'three') {                    if ($env{'form.phase'} eq 'three') {          
             if ($res eq 'text/plain') {              if ($res eq 'text/plain') {
                 open(TESTBANK,"<$dirpath$filename");                  open(TESTBANK,"<",$dirpath.$filename);
                 @{$text} = <TESTBANK>;                  @{$text} = <TESTBANK>;
                 close(TESTBANK);                  close(TESTBANK);
             } elsif ($res eq 'application/rtf') {              } elsif ($res eq 'application/rtf') {
                 my $html = '';                  my $html = '';
 #                my $image_uri = '..'.$pathname;                  my $image_uri = $timestamp;
                 my $image_uri = $pathname;  
                 if ($page_name eq 'Target') {                  if ($page_name eq 'Target') {
                     $image_uri = $urlpath;                      $image_uri = "$webpath/$timestamp";
                 }                  }
                 $image_uri =~ s/\/$//;  
                 my $image_dir;                  my $image_dir;
                 if ($page_name eq 'Blocks') {                  if ($page_name eq 'Blocks') {
                     $image_dir = $dirpath;                      $image_dir = $dirpath;
                     $image_dir =~ s/\/$//;                      $image_dir =~ s/\/$//;
                       $image_dir .= '/'.$timestamp;
                       if (!-e $image_dir) {
                           mkdir($image_dir,0755);
                       }
                 } else {                  } else {
                     $image_dir = $r->dir_config('lonDaemons').'/tmp/'.                      $image_dir = $r->dir_config('lonDaemons').'/tmp/'.
                                  $env{'user.name'}.'_'.$env{'user.domain'}.                                   $env{'user.name'}.'_'.$env{'user.domain'}.
Line 1651  sub parse_datafile { Line 1671  sub parse_datafile {
                 $parser->parse();                  $parser->parse();
                 utf8::decode($html);                  utf8::decode($html);
                 ($text,$header,$css,$js) =                   ($text,$header,$css,$js) = 
                     &parse_htmlcontent($res,$subdir,$html);                      &parse_htmlcontent($res,$subdir,$html,undef,$page_name);
             } elsif ($res eq 'text/html') {              } elsif ($res eq 'text/html') {
                 ($text,$header,$css,$js) =                   ($text,$header,$css,$js) = 
                     &parse_htmlcontent($res,$subdir,undef,$dirpath.$filename);                      &parse_htmlcontent($res,$subdir,undef,$dirpath.$filename,$page_name);
             } else {              } else {
                 $badfile = 1;                  $badfile = 1;
             }              }
Line 1664  sub parse_datafile { Line 1684  sub parse_datafile {
 }  }
   
 sub parse_htmlcontent {  sub parse_htmlcontent {
     my ($res,$subdir,$html,$fullpath) = @_;      my ($res,$subdir,$html,$fullpath,$page_name) = @_;
     my ($p,$fh);      my ($p,$fh);
     if ($res eq 'application/rtf') {      if ($res eq 'application/rtf') {
         $p = HTML::TokeParser->new( \$html );          $p = HTML::TokeParser->new( \$html );
Line 1702  sub parse_htmlcontent { Line 1722  sub parse_htmlcontent {
                     my $contents = $token->[4];                      my $contents = $token->[4];
                     if ($subdir ne '') {                      if ($subdir ne '') {
                         if (($token->[1] eq 'img') && ($token->[2]->{'src'} ne '')) {                          if (($token->[1] eq 'img') && ($token->[2]->{'src'} ne '')) {
                             $contents =~ s/(src=\s*["']?)/$1..\//i;                              if (($res eq 'text/html') || 
                                   ($res eq 'application/rtf') && ($page_name ne 'Target')) {
                                   $contents =~ s/(src=\s*["']?)/$1..\//i;
                               }
                         }                          }
                     }                      }
                     if (($line eq '') && ($current_tag eq 'font')) {                      if (($line eq '') && ($current_tag eq 'font')) {
Line 1758  sub parse_htmlcontent { Line 1781  sub parse_htmlcontent {
 }  }
   
 sub build_image_url {  sub build_image_url {
     my ($urlpath,$item) = @_;      my ($webpath,$item) = @_;
     $item =~ s/(<img[^>]+src=["']?\s*)(\.?\.?\/?)/$1$urlpath/gsi;      $item =~ s/(<img[^>]+src=["']?\s*)(\.?\.?\/?)/$1$webpath/gsi;
     return $item;       return $item;
 }  }
   
 sub print_header {  sub print_header {
     my ($uname,$udom,$javascript,$loadentries,$title) = @_;      my ($uname,$udom,$javascript,$loadentries,$title,$current_page,$pagesref,
           $namesref) = @_;
       my $brcrum = [{'href' => &Apache::loncommon::authorspace("/priv/$udom/$uname/"),
                      'text' => 'Authoring Space'}];
       if ($env{'form.phase'} eq 'three') {
           if (ref($pagesref) eq 'ARRAY') {
               for (my $i=0; $i<$current_page; $i++) {
                   my $goback = 1 + $i - $current_page;
                   if (ref($namesref) eq 'HASH') {
                       if ($namesref->{$pagesref->[$i]} ne '') {
                           if (ref($brcrum) eq 'ARRAY') {
                               my $text = $namesref->{$pagesref->[$i]};
                               my $href;
                               if ($goback == -1) {
                                   $href = 'javascript:backPage();';
                               } else {
                                   $href = 'javascript:history.go('.$goback.')';
                               }
                               push(@{$brcrum}, {'href' => $href,
                                                 'text' => $text});
                           }
                       }
                   }
               }
           }
       }
     my $output = &Apache::loncommon::start_page($title,$javascript,      my $output = &Apache::loncommon::start_page($title,$javascript,
                                              {'add_entries' => $loadentries});                                               {'bread_crumbs' => $brcrum,
                                                 'add_entries' => $loadentries});
     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {      if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
         $output .= '<h3><span class="LC_error">'.&mt('Co-Author').': '.$uname.          $output .= '<p class="LC_info">'
                    &mt(' at ').$udom.'</span></h3>';                   .&mt('Co-Author [_1]',$uname.':'.$udom)
                    .'</p>';
     }      }
     return $output;      return $output;
 }  }
   
 sub topic_bar {  
     my ($imgnum,$title) = @_;  
     my $output = '  
 <div class="LC_topic_bar">  
     <img alt="'.&mt('Step [_1]',$imgnum).  
               ' "src="/res/adm/pages/bl_step'.$imgnum.'.gif" />&nbsp;'.$title.'  
 </div>  
 ';  
     return $output;  
 }  
   
 # ---------------------------------------------------------------- Main Handler  # ---------------------------------------------------------------- Main Handler
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
     my $uname;  
     my $udom;  
     my $javascript = '';  
     my $page_name = '';  
     my $current_page = '';  
     my $qcount = '';  
     my $title = 'Upload testbank questions to Construction Space';  
   
     if ($env{'form.uploaduname'}) {      my $fn=$env{'form.filename'};
         $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.  
             $env{'form.filename'};      if ($env{'form.filename1'}) {
     }         $fn=$env{'form.filename1'}.$env{'form.filename2'};
     ($uname,$udom)=  
         &Apache::loncacc::constructaccess($env{'form.filename'},  
                                           $r->dir_config('lonDefDomain'));  
     unless (($uname) && ($udom)) {  
         $r->log_reason($uname.':'.$udom.' trying to convert testbank file '.  
                        $env{'form.filename'}.' - not authorized',$r->filename);  
         return HTTP_NOT_ACCEPTABLE;  
     }      }
       $fn=~s{\+}{}g;
   
     my ($fn,$filename);      unless ($fn) {
     if ($env{'form.filename'}) {  
         $fn=$env{'form.filename'};  
         $fn=~s/^http\:\/\/[^\/]+\///;  
         $fn=~s/^\///;  
         $fn=~s{(~|priv/)($LONCAPA::username_re)}{};  
         $fn=~s/\/+/\//g;  
     } else {  
         $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.          $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
                        ' unspecified filename for upload', $r->filename);                         ' unspecified filename for upload', $r->filename);
         return HTTP_NOT_FOUND;          return HTTP_NOT_FOUND;
     }      }
   
       my ($uname,$udom) = &Apache::lonnet::constructaccess($fn);
       if (($uname eq '') || ($udom eq '')) {
           $r->log_reason($uname.':'.$udom.' trying to convert testbank file '.
                          $fn.' - not authorized',$r->filename);
           return HTTP_NOT_ACCEPTABLE;
       }
   
       my $javascript = '';
       my $page_name = '';
       my $current_page = '';
       my $qcount = '';
       my $title = 'Upload testbank questions to Authoring Space';
   
 # ----------------------------------------------------------- Start page output  # ----------------------------------------------------------- Start page output
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
   
     my ($filename,$pathname) = &File::Basename::fileparse($fn);      my ($filename,$webpath) = &File::Basename::fileparse($fn);
     my $webpath = '/priv/'.$uname.$pathname;      my $dirpath = $r->dir_config('lonDocRoot').$webpath;
     my $urlpath = '/~'.$uname.$pathname;      my ($res,$subdir,$badfile,$textref,$header,$css,$js,%loadentries,@pages,%names);
     my $dirpath = '/home/'.$uname.'/public_html'.$pathname;  
     my ($res,$subdir,$badfile,$textref,$header,$css,$js,%loadentries);  
   
     if ($env{'form.phase'} eq 'three') {      if ($env{'form.phase'} eq 'three') {
         $current_page = &display_control();          $current_page = &display_control();
         my @pages = ('Welcome','Blocks','Format','Target','Confirmation');          @pages = ('Welcome','Blocks','Format','Target','Confirmation');
           %names = &Apache::lonlocal::texthash(
                      Welcome      => 'Testbank Format',
                      Blocks       => 'Classification',
                      Format       => 'Selection',
                      Target       => 'Result'
           );
         $page_name = $pages[$current_page];          $page_name = $pages[$current_page];
           if ($env{'form.timestamp'} eq '') {
               $env{'form.timestamp'} = time; 
           }
         if ($env{'form.newdir'} ne '') {          if ($env{'form.newdir'} ne '') {
             if ($env{'form.newdir'} =~ /^\Q$dirpath\E(.+)$/) {              if ($env{'form.newdir'} =~ /^\Q$dirpath\E(.+)$/) {
                 $subdir = $1;                  $subdir = $1;
             }              }
         }          }
         ($res,$badfile,$textref,$header,$css,$js) =           ($res,$badfile,$textref,$header,$css,$js) = 
             &parse_datafile($r,$uname,$filename,$pathname,$dirpath,$urlpath,              &parse_datafile($r,$filename,$dirpath,$webpath,$page_name,
                             $page_name,$subdir);                              $subdir,$env{'form.timestamp'});
         if ($page_name eq 'Welcome') {          if ($page_name eq 'Welcome') {
              &jscript_zero($webpath,\$javascript);               &jscript_zero($webpath,\$javascript);
         } elsif ($page_name eq 'Blocks') {          } elsif ($page_name eq 'Blocks') {
Line 1874  sub handler { Line 1913  sub handler {
         }          }
     }      }
   
     $r->print(&print_header($uname,$udom,$javascript,\%loadentries,$title));      $r->print(&print_header($uname,$udom,$javascript,\%loadentries,$title,
                               $current_page,\@pages,\%names));
   
     if ($env{'form.phase'} eq 'three') {      if (($env{'form.phase'} eq 'four') || ($env{'form.phase'} eq 'three')) {
         if ($env{'form.action'} eq 'upload_embedded') {          if ($env{'form.phase'} eq 'four') {
             $r->print(&Apache::lonupload::phasethree($r,$fn,$uname,$udom,'testbank'));              $r->print(&Apache::lonupload::phasefour($r,$fn,$uname,$udom,'testbank'));
               my $current_page = 0; 
               my $js;
               &jscript_zero($webpath,\$js);
               $js = '<script type="text/javascript">'."\n$js\n".'</script>';
               $r->print($js);
               &display_zero($r,$fn,$current_page,$webpath);
           } elsif ($env{'form.phase'} eq 'three') {
               if ($env{'form.action'} eq 'upload_embedded') {
                   my ($result,$flag) = 
                        &Apache::lonupload::phasethree($r,$fn,$uname,$udom,'testbank');
                   $r->print($result);
                   if ($flag eq 'modify_orightml') {
                       undef($page_name); 
                       $r->print('<form name="testbankForm" method="post" action="/adm/testbank">'.
                                 &page_footer('',$fn).'</form>');
                   }
               }
         }          }
         if ($badfile) {          if ($badfile) {
             &file_error($r,$uname,$fn,$current_page,$webpath,$res);              &file_error($r,$fn,$current_page,$webpath,$res);
         } else {                  } else {
             &display_zero ($r,$uname,$fn,$current_page,$webpath) if $page_name eq 'Welcome';              &display_zero ($r,$fn,$current_page,$webpath) if $page_name eq 'Welcome';
             &display_one ($r,$uname,$fn,$current_page,$textref,$header) if $page_name eq 'Blocks';              &display_one ($r,$fn,$current_page,$textref,$header) if $page_name eq 'Blocks';
             &display_two ($r,$uname,$fn,$current_page,$textref,$header,$qcount) if $page_name eq 'Format';              &display_two ($r,$fn,$current_page,$textref,$header,$qcount) if $page_name eq 'Format';
             &display_three ($r,$uname,$fn,$current_page,$textref,$res,$header,$urlpath,$qcount) if $page_name eq 'Target';              &display_three ($r,$fn,$current_page,$textref,$res,$header,$webpath,$qcount) if $page_name eq 'Target';
             &final_display ($r,$uname,$fn,$current_page,$textref,$res,$header,$css,$js,$webpath,$dirpath,$subdir) if $page_name eq 'Confirmation';              &final_display ($r,$fn,$current_page,$textref,$res,$header,$css,$js,$webpath,$dirpath,$subdir) if $page_name eq 'Confirmation';
         }          }
     } elsif ($env{'form.phase'} eq 'two') {      } elsif ($env{'form.phase'} eq 'two') {
         my ($result,$flag) = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'testbank');          my ($result,$flag) = &Apache::lonupload::phasetwo($r,$fn,'testbank');
         $r->print($result);          $r->print($result);
         if ($flag eq 'ok') {          if ($flag eq 'ok') {
             my $current_page = 0;              my $current_page = 0;
Line 1898  sub handler { Line 1955  sub handler {
             &jscript_zero($webpath,\$js);              &jscript_zero($webpath,\$js);
             $js = '<script type="text/javascript">'."\n$js\n".'</script>';              $js = '<script type="text/javascript">'."\n$js\n".'</script>';
             $r->print($js);              $r->print($js);
             &display_zero($r,$uname,$fn,$current_page,$webpath);              &display_zero($r,$fn,$current_page,$webpath);
         } elsif ($flag eq 'embedded') {          } elsif ($flag eq 'embedded') {
             $r->print($js.'<form name="testbankForm" method="post" action="/adm/testbank">'.              $r->print($js.'<form name="testbankForm" method="post" action="/adm/testbank">'.
                       &page_footer('',$uname,$fn).'</form>');                        &page_footer('',$fn).'</form>');
         }          }
     } else {      } else {
         &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'testbank');          &Apache::lonupload::phaseone($r,$fn,'testbank',$uname,$udom);
     }      }
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
     return OK;      return OK;

Removed from v.1.17  
changed lines
  Added in v.1.45


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>