--- loncom/publisher/testbankimport.pm 2006/04/10 22:30:31 1.10 +++ loncom/publisher/testbankimport.pm 2013/04/11 14:59:58 1.38 @@ -1,5 +1,5 @@ # Handler for parsing text upload problem descriptions into .problems -# $Id: testbankimport.pm,v 1.10 2006/04/10 22:30:31 albertel Exp $ +# $Id: testbankimport.pm,v 1.38 2013/04/11 14:59:58 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,13 +28,18 @@ package Apache::testbankimport; use strict; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); use Apache::lonnet; use HTML::Entities(); use Apache::lonlocal; use Apache::lonupload; +use Apache::londocs; use File::Basename(); +use LONCAPA(); +use File::MMagic; +use XML::DOM; +use RTF::HTMLConverter; +use HTML::TokeParser; # ---------------------------------------------------------------- Display Control sub display_control { @@ -55,6 +60,46 @@ sub calculate_page($$) { return 0 if $dir eq 'BackToStart'; } +sub jscript_zero { + my ($webpath,$jsref) = @_; + my $start_page = + &Apache::loncommon::start_page('Create Testbank directory',undef, + {'only_body' => 1, + 'js_ready' => 1,}); + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + my %lt = &Apache::lonlocal::texthash( + loca => 'Location', + newd => 'New Directory', + ente => 'Enter the name of the new directory where you will save the converted testbank questions', + go => 'Go', + ); + $$jsref = <<"END_SCRIPT"; +function createWin() { + document.info.newdir.value = ""; + newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes") + newWindow.document.open() + newWindow.document.write('$start_page') + newWindow.document.write("\\n") + newWindow.document.write("
\\n") - newWindow.document.write(" | Location: $fullpathNew Directory | |
\\n") - newWindow.document.write(" |
- |
-The Testbank Upload utility can be used by LON-CAPA authors to convert multiple choice, multiple answer correct, fill-in-the-blank, ordering/ranking, true/false and essay 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.
-
|
-
-
|
-
- | -||
- | -- Result of conversion of tesbank questions to LON-CAPA problems. - | -|
- | ||
Individual problem files have been created from the problems included in the textbank file:
-
| ||
- | The problems must be published before they can be used in a course. | - |); + if ($result[$i] eq 'ok') { + $successes .= ''.$numid[$i].': '. + $qn_file[$i].'|
- | No destination file was selected or created, so import of your questions could not proceed. - Please return to the previous page and select a valid file into which to import the questions. - - - - - - - - - |); - for (my $i=0; $i<$blocks; $i++) { - $r->print(qq| - - - - - - |); - } - $r->print(<<"END_OF_FAIL"); - | -|
-
|
-
'.&mt('No destination directory was available so import of questions could not proceed.').'
'. + &page_footer($env{'form.newdir'},$fn,$page,$webpath,$subdir,$state).''); + } return; - } - $r->print(<<"END_OF_BODY"); - - - - - - -- - | -
'.&mt('Testbank data uploaded to the server').'
'."\n". + '
'; + return $output; +} + +sub page_footer { + my ($newdir,$fn,$page,$webpath,$subdir,$state) = @_; + my $prevval = &mt('Previous Page'); + my $nextval = &mt('Next Page'); + my $prevclick = 'javascript:backPage();'; + my $nextclick = 'javascript:nextPage();'; + my $go = ''; + if (($page == 0) || ($state eq 'badfile')) { + $go = 'NextPage'; + $prevval = &mt('Exit Now'); + $prevclick = 'javascript:location.href='."'$webpath';"; + $nextclick = 'javascript:submit();' + } elsif ($page == 3) { + $nextval = &mt('Complete Testbank Conversion'); + } elsif ($page == 4) { + if (($state ne 'existing') && ($state ne 'unchecked')) { + my $destdir = $webpath; + if ($subdir ne '') { + $destdir = $webpath.$subdir; + } + $prevval = &mt('Back to Directory'); + $prevclick = 'javascript:location.href='."'$destdir';"; + } + } + my $output = ' + + + + + + '; + if ($page ne '') { + $output .= ' ++ + | '; + if (($page < 4) && ($state ne 'badfile')) { + $output .= ' ++ | + + | '; + } + $output .= '
'.&mt('Extraction of questions is only possible for the following file types:'). + '
' + .&mt('Co-Author [_1]',$uname.':'.$udom) + .'
'; + } + return $output; +} # ---------------------------------------------------------------- Main Handler sub handler { my $r=shift; - my $uname; - my $udom; - my $javascript = ''; - my $page_name = ''; - my $current_page = ''; - my $qcount = ''; -# -# phase two: re-attach user -# - if ($env{'form.uploaduname'}) { - $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'. - $env{'form.filename'}; - } - ($uname,$udom)= - &Apache::loncacc::constructaccess($env{'form.filename'}, - $r->dir_config('lonDefDomain')); - unless (($uname) && ($udom)) { - $r->log_reason($uname.' at '.$udom. - ' trying to publish file '.$env{'form.filename'}. - ' - not authorized', - $r->filename); - return HTTP_NOT_ACCEPTABLE; + + my $fn=$env{'form.filename'}; + + if ($env{'form.filename1'}) { + $fn=$env{'form.filename1'}.$env{'form.filename2'}; } - - my $fn; - my $badfile = 0; - if ($env{'form.filename'}) { - $fn=$env{'form.filename'}; - $fn=~s/^http\:\/\/[^\/]+\///; - $fn=~s/^\///; - $fn=~s/(\~|priv\/)(\w+)//; - $fn=~s/\/+/\//g; - } else { + $fn=~s{\+}{}g; + + unless ($fn) { $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for upload', $r->filename); return HTTP_NOT_FOUND; } - my $pathname = &File::Basename::dirname($fn); - my $fullpath = '/priv/'.$uname.$pathname; - unless ($pathname eq '/') { - $fullpath .= '/'; - } - my $dirpath = '/home/'.$uname.'/public_html'; - - my @text = (); - if ($env{'form.phase'} eq 'three') { - if (-e "$dirpath$fn") { - open(TESTBANK,"<$dirpath$fn"); - @text =