--- loncom/publisher/testbankimport.pm 2006/12/06 22:22:39 1.11 +++ loncom/publisher/testbankimport.pm 2009/04/04 21:45:57 1.21 @@ -1,5 +1,5 @@ # Handler for parsing text upload problem descriptions into .problems -# $Id: testbankimport.pm,v 1.11 2006/12/06 22:22:39 albertel Exp $ +# $Id: testbankimport.pm,v 1.21 2009/04/04 21:45:57 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,8 +34,13 @@ 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 { @@ -56,6 +61,45 @@ 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'},$uname,$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,$uname,$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]:[_2]',$uname,$udom) + .'
'; + } + return $output; +} + +sub topic_bar { + my ($imgnum,$title) = @_; + my $output = ' + +'; + return $output; +} # ---------------------------------------------------------------- Main Handler sub handler { @@ -1713,9 +1800,8 @@ sub handler { my $page_name = ''; my $current_page = ''; my $qcount = ''; -# -# phase two: re-attach user -# + my $title = 'Upload testbank questions to Construction Space'; + if ($env{'form.uploaduname'}) { $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'. $env{'form.filename'}; @@ -1724,18 +1810,15 @@ sub handler { &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); + $r->log_reason($uname.':'.$udom.' trying to convert testbank file '. + $env{'form.filename'}.' - not authorized',$r->filename); return HTTP_NOT_ACCEPTABLE; } - - my $fn; - my $badfile = 0; + + my ($fn,$filename); if ($env{'form.filename'}) { $fn=$env{'form.filename'}; - $fn=~s/^http\:\/\/[^\/]+\///; + $fn=~s/^https?\:\/\/[^\/]+\///; $fn=~s/^\///; $fn=~s{(~|priv/)($LONCAPA::username_re)}{}; $fn=~s/\/+/\//g; @@ -1744,78 +1827,90 @@ sub handler { ' 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 =