Diff for /loncom/publisher/testbankimport.pm between versions 1.16 and 1.18

version 1.16, 2008/07/08 07:17:46 version 1.18, 2008/09/24 19:48:29
Line 1163  sub page_footer { Line 1163  sub page_footer {
     my $nextval = &mt('Next Page');      my $nextval = &mt('Next Page');
     my $prevclick = 'javascript:backPage();';      my $prevclick = 'javascript:backPage();';
     my $nextclick = 'javascript:nextPage();';      my $nextclick = 'javascript:nextPage();';
     my $go = '';       my $go = '';
     if ($page == 0) {      if (($page == 0) || ($state eq 'badfile')) {
         $go = 'NextPage';          $go = 'NextPage';
         $prevval = &mt('Exit Now');          $prevval = &mt('Exit Now');
         $prevclick = 'javascript:location.href='."'$webpath';";          $prevclick = 'javascript:location.href='."'$webpath';";
Line 1187  sub page_footer { Line 1187  sub page_footer {
        <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 1195  sub page_footer { Line 1196  sub page_footer {
          <td>           <td>
           <input type="button" name="backpage" value="'.$prevval.'" onclick="'.$prevclick.'" />            <input type="button" name="backpage" value="'.$prevval.'" onclick="'.$prevclick.'" />
          </td>';           </td>';
         if ($page < 4)  {          if (($page < 4) && ($state ne 'badfile'))  {
             $output .= '              $output .= '
          <td>&nbsp;</td>           <td>&nbsp;</td>
          <td>           <td>
Line 1327  sub create_mcq { Line 1328  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>
  <startouttext />';   <startouttext />';
Line 1599  sub probfile_name { Line 1599  sub probfile_name {
 }  }
   
 sub file_error {  sub file_error {
     my ($r,$uname,$fn,$current_page);      my ($r,$uname,$fn,$current_page,$webpath,$res) = @_;
     $r->print("No data here");      $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:').
                 '<ul><li>'.&mt('plain text').'</li><li>RTF</li><li>HTML</li></ul>'.
                 &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').
                '</form>');
       return;
 }  }
   
 sub parse_datafile {  sub parse_datafile {
     my ($r,$uname,$filename,$pathname,$dirpath,$urlpath,$page_name,$subdir) = @_;      my ($r,$uname,$filename,$pathname,$dirpath,$urlpath,$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 1617  sub parse_datafile { Line 1623  sub parse_datafile {
                 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 = $urlpath.'/'.$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 1645  sub parse_datafile { Line 1653  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 1658  sub parse_datafile { Line 1666  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 1696  sub parse_htmlcontent { Line 1704  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 1830  sub handler { Line 1841  sub handler {
         $current_page = &display_control();          $current_page = &display_control();
         my @pages = ('Welcome','Blocks','Format','Target','Confirmation');          my @pages = ('Welcome','Blocks','Format','Target','Confirmation');
         $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;
Line 1837  sub handler { Line 1851  sub handler {
         }          }
         ($res,$badfile,$textref,$header,$css,$js) =           ($res,$badfile,$textref,$header,$css,$js) = 
             &parse_datafile($r,$uname,$filename,$pathname,$dirpath,$urlpath,              &parse_datafile($r,$uname,$filename,$pathname,$dirpath,$urlpath,
                             $page_name,$subdir);                              $page_name,$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 1875  sub handler { Line 1889  sub handler {
             $r->print(&Apache::lonupload::phasethree($r,$fn,$uname,$udom,'testbank'));              $r->print(&Apache::lonupload::phasethree($r,$fn,$uname,$udom,'testbank'));
         }          }
         if ($badfile) {          if ($badfile) {
             &file_error($r,$uname,$fn,$current_page);              &file_error($r,$uname,$fn,$current_page,$webpath,$res);
         } else {                  } else {        
             &display_zero ($r,$uname,$fn,$current_page,$webpath) if $page_name eq 'Welcome';              &display_zero ($r,$uname,$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,$uname,$fn,$current_page,$textref,$header) if $page_name eq 'Blocks';

Removed from v.1.16  
changed lines
  Added in v.1.18


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